Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions src/net/lewisship/cli_tools/impl.clj
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@
(defn- compose-command-path
[tool-name command-path]
(when tool-name
[:bold.green
tool-name
(when (seq command-path)
(list
" "
(string/join " " command-path)))]))
(list
[(style :tool-name) tool-name]
(when (seq command-path)
(list " "
[(style :command-path)
(string/join " " command-path)])))))

(defn command-path
[]
Expand Down Expand Up @@ -751,7 +751,8 @@
(reduce max 0)))]
(when container-map
(pout (when recurse? "\n")
[(style :command) (string/join " " (:command-path container-map))]
(compose-command-path (:tool-name *tool-options*)
(:command-path container-map))
" - "
(or (some-> container-map :group-doc cleanup-docstring)
(missing-doc))))
Expand Down
2 changes: 1 addition & 1 deletion test-resources/excess-values.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Error in harness collect: Unexpected argument 'the-extra'
Error in harness collect: Unexpected argument 'the-extra'
2 changes: 1 addition & 1 deletion test-resources/help-incomplete-nested.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
group-test: group nested is incomplete; butterfly or leaf could follow; use group-test group nested --help (or -h) to list commands
group-test: group nested is incomplete; butterfly or leaf could follow; use group-test group nested --help (or -h) to list commands
2 changes: 1 addition & 1 deletion test-resources/help-incomplete.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
group-test: group is incomplete; echo, edit, or nested could follow; use group-test group --help (or -h) to list commands
group-test: group is incomplete; echo, edit, or nested could follow; use group-test group --help (or -h) to list commands
2 changes: 1 addition & 1 deletion test-resources/insufficient-values.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Error in harness collect: No value for required argument VAL
Error in harness collect: No value for required argument VAL
2 changes: 1 addition & 1 deletion test-resources/let-directive.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Error in harness set-mode: Failed to validate "-m unknown": Must be one of async, batch, real-time
Error in harness set-mode: Failed to validate "-m unknown": Must be one of async, batch, real-time
2 changes: 1 addition & 1 deletion test-resources/messy-full-help.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Commands:
messy: Messy command
simple: Simple command

messy - Messy command and group at same time
bigmess messy - Messy command and group at same time

Commands:
nested: Command nested under messy group/command
2 changes: 1 addition & 1 deletion test-resources/pos-arg-validation-failure.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Error in harness configure: HOST: must be a URL
Error in harness configure: HOST: must be a URL
2 changes: 1 addition & 1 deletion test-resources/sub-group-help.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
group - Grouped commands
group-test group - Grouped commands

Commands:
echo: Echo a string
Expand Down
2 changes: 1 addition & 1 deletion test-resources/tool-help-group-full.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Commands:
group: This provides the default documentation for the entire group
help: List available commands

group - This provides the default documentation for the entire group.
test-harness group - This provides the default documentation for the entire group.

The full doc may span multiple lines.

Expand Down
4 changes: 2 additions & 2 deletions test-resources/tool-help-grouped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ Commands:
group: Grouped commands
help: List available commands

group - Grouped commands
group-test group - Grouped commands

Commands:
echo: Echo a string
edit: Edit a whatever
nested: Nested commands inside group

group nested - Nested commands inside group
group-test group nested - Nested commands inside group

Commands:
butterfly: Nested command butterfly
Expand Down
2 changes: 1 addition & 1 deletion test-resources/unknown-option.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Errors in harness configure:
Errors in harness configure:
Unknown option: "--debug"
No value for required argument HOST
7 changes: 5 additions & 2 deletions test/net/lewisship/abort_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@
(deftest abort-with-message
(binding [ansi/*color-enabled* true]
(is (match? {:status 1
:err (compose [:bold.green "tool category command"] ": base message" "\n")}
:err (compose [:bold.green "tool"]
" "
[:bold.green "category command"]
": base message" "\n")}
(capture-result
(abort (command-path) ": " "base message"))))))
(abort (command-path) ": " "base message"))))))


(deftest abort-with-several-messages
Expand Down
6 changes: 5 additions & 1 deletion test/net/lewisship/cli_tools/bb_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@
(deftest can-find-cli-commands
(is (match?
{:status 0
:out "bb - BB CLI commands\n\nCommands:\n alpha: This command take a symbol and a long\n find: Find by id\n"}
:out-lines ["bb-cli bb - BB CLI commands"
""
"Commands:"
" alpha: This command take a symbol and a long"
" find: Find by id"]}
(dispatch "bb" "-h"))))

(deftest can-invoke-command-with-default-name
Expand Down
15 changes: 12 additions & 3 deletions test/net/lewisship/cli_tools_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@
:cache-dir nil}]
(f))))

(defn- capture
"Used when output changes to capture new output (the embedded ANSI sequences are hard to work with."
([file result]
(capture file :out result))
([file k result]
(let [content (get result k)]
(print content)
(spit (str "test-resources/" file ".txt") content))))

;; An example to test around

(defcommand configure
Expand Down Expand Up @@ -216,9 +225,9 @@
(is (match? {:status 0
:out (slurp "test-resources/tool-help-group-full.txt")}
(dispatch-with-result {:tool-name "test-harness"
:groups
{"group" {:namespaces '[net.lewisship.group-default-ns
net.lewisship.example-ns]}}
:groups
{"group" {:namespaces '[net.lewisship.group-default-ns
net.lewisship.example-ns]}}
:arguments ["help" "-c" "all"]}))))

(deftest help-with-search-term
Expand Down
Loading