|
306 | 306 | (recur (dissoc cmdspec :flags) cli-args args (conj seen-prefixes args) flags)) |
307 | 307 |
|
308 | 308 | :else |
309 | | - (recur (dissoc cmdspec :flags) cli-args (conj args (str/replace arg #"^\\(.)" (fn [[_ o]] o))) (conj seen-prefixes args) flags))))) |
| 309 | + (recur (dissoc cmdspec :flags) |
| 310 | + cli-args |
| 311 | + (conj args (str/replace arg #"^\\(.)" (fn [[_ o]] o))) |
| 312 | + (conj seen-prefixes args) |
| 313 | + flags))))) |
310 | 314 |
|
311 | 315 | (defn missing-flags |
312 | 316 | "Return a set of required flags in `flagmap` not present in `opts`, or `nil` if |
|
337 | 341 |
|
338 | 342 | (cond |
339 | 343 | command |
340 | | - (if (or (:help opts) (< (count pos-args) (count argnames))) |
| 344 | + (if (:help opts) |
341 | 345 | (print-help program-name doc [] argnames flagpairs) |
342 | 346 | (binding [*opts* (-> opts |
343 | 347 | (dissoc ::middleware) |
|
359 | 363 | argnames (:argnames command-match) |
360 | 364 | arg-count (count argnames)] |
361 | 365 | (cond |
362 | | - command-match |
| 366 | + (and command-match |
| 367 | + (<= arg-count (count pos-args))) |
363 | 368 | (dispatch* |
364 | 369 | (-> cmdspec |
365 | 370 | (dissoc :command :commands) |
|
372 | 377 |
|
373 | 378 | (or (nil? command-match) |
374 | 379 | (nil? commands) |
375 | | - (:help opts)) |
376 | | - (print-help program-name doc (for [[k v] command-pairs] |
377 | | - [k (if (:commands v) |
378 | | - (update v :commands prepare-cmdpairs) |
379 | | - v)]) |
380 | | - argnames |
381 | | - flagpairs) |
| 380 | + (:help opts) |
| 381 | + (< (count pos-args) arg-count)) |
| 382 | + (do |
| 383 | + (cond |
| 384 | + (or (nil? command-match) (nil? commands)) |
| 385 | + (println "No matching command found:" cmd "\n") |
| 386 | + (< (count pos-args) arg-count) |
| 387 | + (println "Positional arguments missing:" |
| 388 | + (->> argnames |
| 389 | + (drop (count pos-args)) |
| 390 | + (map #(str "<" (name %) ">")) |
| 391 | + (str/join " ")) |
| 392 | + "\n")) |
| 393 | + (print-help program-name doc (for [[k v] command-pairs] |
| 394 | + [k (if (:commands v) |
| 395 | + (update v :commands prepare-cmdpairs) |
| 396 | + v)]) |
| 397 | + argnames |
| 398 | + flagpairs)) |
382 | 399 |
|
383 | 400 | :else |
384 | 401 | (parse-error! "Expected either :command or :commands key in" cmdspec)))))) |
|
0 commit comments