diff --git a/CHANGELOG.md b/CHANGELOG.md index 3de7e69..36e8e1d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,11 +1,9 @@ # Unreleased -## Added - -## Fixed - ## Changed +- Exit with error message if conditional arguments are missing + # 0.8.39 (2024-05-24 / e967e9c) ## Added @@ -94,4 +92,4 @@ approaching the envisioned scope for this library. - subcommand handling - rudimentary flag handling -- help text generation \ No newline at end of file +- help text generation diff --git a/src/lambdaisland/cli.clj b/src/lambdaisland/cli.clj index e29beee..e253280 100644 --- a/src/lambdaisland/cli.clj +++ b/src/lambdaisland/cli.clj @@ -42,10 +42,13 @@ (defn long? [f] (re-find #"^--.*" f)) -(defn print-help [cmd-name doc command-pairs flagpairs] +(defn print-help [cmd-name doc command-pairs argnames flagpairs] (let [desc #(str (first (str/split (:doc % "") #"\R")) (when-let [d (:default %)] (str " (default " (pr-str d) ")")))] (println (str "Usage: " cmd-name + (when (seq argnames) + (str/join (for [n argnames] + (str " <" (name n) ">")))) (str/join (for [[_ {:keys [flags argdoc]}] flagpairs] (str " [" (str/join " | " flags) argdoc "]"))) (when (seq command-pairs) @@ -334,8 +337,8 @@ (cond command - (if (:help opts) - (print-help program-name doc [] flagpairs) + (if (or (:help opts) (< (count pos-args) (count argnames))) + (print-help program-name doc [] argnames flagpairs) (binding [*opts* (-> opts (dissoc ::middleware) (update ::argv (fnil into []) pos-args) @@ -374,6 +377,7 @@ [k (if (:commands v) (update v :commands prepare-cmdpairs) v)]) + argnames flagpairs) :else