Skip to content

Commit 063ebd7

Browse files
committed
For messy commands, show command usage after group help
1 parent c597792 commit 063ebd7

2 files changed

Lines changed: 23 additions & 10 deletions

File tree

src/net/lewisship/cli_tools/impl.clj

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -906,11 +906,14 @@
906906
invoke-last-command-fn nil]
907907
(cond-let
908908
(#{"-h" "--help"} term)
909-
(if invoke-last-command-fn
910-
(invoke-last-command-fn)
911-
(do
912-
(print-commands nil container-map commands-map false)
913-
(exit 0)))
909+
(do
910+
(print-commands nil container-map commands-map false)
911+
;; This is the ugly mixed case where its a group and a command; we present
912+
;; the group first then the command.
913+
(when invoke-last-command-fn
914+
(println)
915+
(invoke-last-command-fn))
916+
(exit 0))
914917

915918
:let [possible-commands commands-map
916919
matchable-terms (keys possible-commands)]

test/net/lewisship/cli_tools/messy_test.clj

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,21 @@
3939
(dispatch "mess" "kiwi"))))
4040

4141
(deftest help-for-messy-command-shows-command-help
42-
(let [{:keys [status out]} (dispatch "mess" "-h")]
43-
(is (= 0 status))
44-
(is (string/includes? out "Usage:"))
45-
(is (string/includes? out "NAME"))
46-
(is (not (string/includes? out "nested")))))
42+
(is (match? {:status 0
43+
:out-lines ["bigmess messy - Messy command and group at same time"
44+
""
45+
"Commands:"
46+
" nested: Command nested under messy group/command"
47+
""
48+
"Usage: bigmess messy [OPTIONS] NAME"
49+
"Messy command."
50+
""
51+
"Options:"
52+
" -h, --help This command summary"
53+
""
54+
"Arguments:"
55+
" NAME: Name to print"]}
56+
(dispatch "mess" "-h"))))
4757

4858
(comment
4959

0 commit comments

Comments
 (0)