From 23127dd5e194d08506e9844b813d76ba4a86ae54 Mon Sep 17 00:00:00 2001 From: "Howard M. Lewis Ship" Date: Tue, 28 Oct 2025 11:39:07 -0700 Subject: [PATCH] Include the tool name in group help --- src/net/lewisship/cli_tools/impl.clj | 15 ++++++++------- test-resources/excess-values.txt | 2 +- test-resources/help-incomplete-nested.txt | 2 +- test-resources/help-incomplete.txt | 2 +- test-resources/insufficient-values.txt | 2 +- test-resources/let-directive.txt | 2 +- test-resources/messy-full-help.txt | 2 +- test-resources/pos-arg-validation-failure.txt | 2 +- test-resources/sub-group-help.txt | 2 +- test-resources/tool-help-group-full.txt | 2 +- test-resources/tool-help-grouped.txt | 4 ++-- test-resources/unknown-option.txt | 2 +- test/net/lewisship/abort_test.clj | 7 +++++-- test/net/lewisship/cli_tools/bb_test.clj | 6 +++++- test/net/lewisship/cli_tools_test.clj | 15 ++++++++++++--- 15 files changed, 42 insertions(+), 25 deletions(-) diff --git a/src/net/lewisship/cli_tools/impl.clj b/src/net/lewisship/cli_tools/impl.clj index 502afdc..b6122df 100644 --- a/src/net/lewisship/cli_tools/impl.clj +++ b/src/net/lewisship/cli_tools/impl.clj @@ -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 [] @@ -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)))) diff --git a/test-resources/excess-values.txt b/test-resources/excess-values.txt index d03241e..ff66cec 100644 --- a/test-resources/excess-values.txt +++ b/test-resources/excess-values.txt @@ -1 +1 @@ -Error in harness collect: Unexpected argument 'the-extra' +Error in harness collect: Unexpected argument 'the-extra' diff --git a/test-resources/help-incomplete-nested.txt b/test-resources/help-incomplete-nested.txt index f76b77f..a618d50 100644 --- a/test-resources/help-incomplete-nested.txt +++ b/test-resources/help-incomplete-nested.txt @@ -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 diff --git a/test-resources/help-incomplete.txt b/test-resources/help-incomplete.txt index 3148ad3..934b351 100644 --- a/test-resources/help-incomplete.txt +++ b/test-resources/help-incomplete.txt @@ -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 diff --git a/test-resources/insufficient-values.txt b/test-resources/insufficient-values.txt index 22078cd..79ad5cc 100644 --- a/test-resources/insufficient-values.txt +++ b/test-resources/insufficient-values.txt @@ -1 +1 @@ -Error in harness collect: No value for required argument VAL +Error in harness collect: No value for required argument VAL diff --git a/test-resources/let-directive.txt b/test-resources/let-directive.txt index d6efd4a..145d76c 100644 --- a/test-resources/let-directive.txt +++ b/test-resources/let-directive.txt @@ -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 diff --git a/test-resources/messy-full-help.txt b/test-resources/messy-full-help.txt index 198f518..b47feb0 100644 --- a/test-resources/messy-full-help.txt +++ b/test-resources/messy-full-help.txt @@ -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 diff --git a/test-resources/pos-arg-validation-failure.txt b/test-resources/pos-arg-validation-failure.txt index 503e075..ea60b32 100644 --- a/test-resources/pos-arg-validation-failure.txt +++ b/test-resources/pos-arg-validation-failure.txt @@ -1 +1 @@ -Error in harness configure: HOST: must be a URL +Error in harness configure: HOST: must be a URL diff --git a/test-resources/sub-group-help.txt b/test-resources/sub-group-help.txt index b7ea586..ed5a4f3 100644 --- a/test-resources/sub-group-help.txt +++ b/test-resources/sub-group-help.txt @@ -1,4 +1,4 @@ -group - Grouped commands +group-test group - Grouped commands Commands: echo: Echo a string diff --git a/test-resources/tool-help-group-full.txt b/test-resources/tool-help-group-full.txt index 41be7ea..6edcb07 100644 --- a/test-resources/tool-help-group-full.txt +++ b/test-resources/tool-help-group-full.txt @@ -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. diff --git a/test-resources/tool-help-grouped.txt b/test-resources/tool-help-grouped.txt index 3d76c48..d8c6c9a 100644 --- a/test-resources/tool-help-grouped.txt +++ b/test-resources/tool-help-grouped.txt @@ -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 diff --git a/test-resources/unknown-option.txt b/test-resources/unknown-option.txt index e71f3ef..b908143 100644 --- a/test-resources/unknown-option.txt +++ b/test-resources/unknown-option.txt @@ -1,3 +1,3 @@ -Errors in harness configure: +Errors in harness configure: Unknown option: "--debug" No value for required argument HOST diff --git a/test/net/lewisship/abort_test.clj b/test/net/lewisship/abort_test.clj index ed6562a..5f56f9d 100644 --- a/test/net/lewisship/abort_test.clj +++ b/test/net/lewisship/abort_test.clj @@ -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 diff --git a/test/net/lewisship/cli_tools/bb_test.clj b/test/net/lewisship/cli_tools/bb_test.clj index 5208bee..4d6ba0c 100644 --- a/test/net/lewisship/cli_tools/bb_test.clj +++ b/test/net/lewisship/cli_tools/bb_test.clj @@ -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 diff --git a/test/net/lewisship/cli_tools_test.clj b/test/net/lewisship/cli_tools_test.clj index 1dd2a9d..c19fa68 100644 --- a/test/net/lewisship/cli_tools_test.clj +++ b/test/net/lewisship/cli_tools_test.clj @@ -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 @@ -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