         pan-sources (map #(File. ^String %) files)]
     (org.quattor.pan.Compiler/run compiler-options nil pan-sources)))
 
+(def cli-options
+  [;; First three strings describe a short-option, long-option with optional
+   ;; example argument description, and a description. All three are optional
+   ;; and positional. short and long option must be replaced by nil if absent.
+   [nil "--base-dir DIR" "base directory for templates" 
+    :default (current-directory) :parse-fn parse-directory]
+   [nil "--output-dir DIR" "output directory" 
+    :default (current-directory) :parse-fn parse-directory]
+   [nil "--java-opts OPTS" "options for JVM"]
+   ["-v" "--verbose" "show statistics and progress" :default false :flag true]
+   ["-h" "--help" "print command help" :default false :flag true]])
+   
+(defn usage [options-summary]
+  (->> ["This tool processes annotations in pan templates."
+        ""
+        "Usage: panc-annotations [options] files"
+        ""
+        "Options:"
+        options-summary
+        ""
+        "Arguments:"
+        "  files    space-separated list of pan template files relative to base directory"
+        ""]
+       (string/join \newline)))
+
+(defn error-msg [errors]
+  (str "The following errors occurred while parsing your command:\n\n"
+       (string/join \newline errors)))
+
+(defn exit [status msg]
+  (println msg)
+  (System/exit status))
+
 (defn -main [& args]
-  (let [[options files banner]
-        (cli args
-             ["--base-dir" "base directory for templates" 
-              :default (current-directory) :parse-fn parse-directory]
-             ["--output-dir" "output directory" 
-              :default (current-directory) :parse-fn parse-directory]
-             ["--java-opts" "options for JVM"]
-             ["-v" "--verbose" "show statistics and progress" :default false :flag true]
-             ["-h" "--help" "print command help" :default false :flag true])]
-    (when (:help options)
-      (println banner)
-      (System/exit 0))
+  (let [{:keys [options files errors summary]} (parse-opts args cli-options)]
+    (cond
+      (:help options) (exit 0 (usage summary))
+      (< (count args) 1) (exit 1 (usage summary))
+      errors (exit 1 (error-msg errors)))
     (let [^CompilerResults results (generate-annotations options files)]
       (if-let [errors (.formatErrors results)]
         (println errors)
         "")
       (println (.formatStats results)))))
+

    (list (create-absolute-file ""))))

(defn parse-directory [dir]
  (if (str/blank? dir)
    (current-directory)
    (create-absolute-file dir)))


(ns org.quattor.pan.pan-annotations
  (:gen-class)
  (:require [clojure.tools.cli :refer [parse-opts]]
            [clojure.string :as string])
  (:import (java.io File)
           (org.quattor.pan CompilerOptions CompilerResults)))

