diff --git a/CHANGES.md b/CHANGES.md index 32ea276..2c0006b 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,7 +2,6 @@ *BREAKING CHANGES* -* JDK 17 is now required when using Clojure * Groups are now defined in the options passed to `net.lewisship.cli-tools/dispatch`, not in namespace metadata * Command names are matched as prefixes (not substrings) diff --git a/README.md b/README.md index 793a006..8aef73b 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,6 @@ Documentation starts with [the overview](doc/overview.md). ## Compatibility `cli-tools` is compatible with Clojure 1.11 and above, and w/ Babashka. -For Clojure, it requires JDK 17 or above. ## License diff --git a/src/net/lewisship/cli_tools.clj b/src/net/lewisship/cli_tools.clj index edc28dc..6554fc9 100644 --- a/src/net/lewisship/cli_tools.clj +++ b/src/net/lewisship/cli_tools.clj @@ -170,16 +170,12 @@ ;; it can also be a map with key :options test-mode?# (impl/command-map? args#) command-spec# ~(select-keys parsed-interface parse-cli-keys)] + ;; introspection mode is used primarily by completions; it invokes the function with no arguments + ;; (but with the flag on) and the command-spec is returned, from which completions are generated. (if impl/*introspection-mode* command-spec# - (let [~command-map-symbol (cond - test-mode?# + (let [~command-map-symbol (if test-mode?# {:options (first args#)} - - impl/*introspection-mode* - command-spec# - - :else (impl/parse-cli ~command-name' ~docstring args# diff --git a/src/net/lewisship/cli_tools/cache.cljc b/src/net/lewisship/cli_tools/cache.cljc index 8e042c1..fa4195d 100644 --- a/src/net/lewisship/cli_tools/cache.cljc +++ b/src/net/lewisship/cli_tools/cache.cljc @@ -9,7 +9,6 @@ [clj-commons.ansi :refer [perr]] #?(:bb [babashka.classpath :as cp])) (:import (java.io File) - (java.util HexFormat) (java.nio ByteBuffer) (java.security MessageDigest))) @@ -59,10 +58,10 @@ ;; Adding or removing a file (even if no other files are touched) will change the digest. (update-digest-recursively digest f)))) -(defn- hex-string - [^bytes input] - (-> (HexFormat/of) - (.formatHex input))) +(defn- hex-string [^bytes input] + (let [sb (StringBuilder.)] + (run! #(.append sb (format "%X" %)) input) + (str sb))) (defn classpath-digest "Passed the tool options, return a hex string of the SHA-1 digest of the files from the classpath and diff --git a/src/net/lewisship/cli_tools/impl.clj b/src/net/lewisship/cli_tools/impl.clj index 516a95f..aae4057 100644 --- a/src/net/lewisship/cli_tools/impl.clj +++ b/src/net/lewisship/cli_tools/impl.clj @@ -906,11 +906,14 @@ invoke-last-command-fn nil] (cond-let (#{"-h" "--help"} term) - (if invoke-last-command-fn - (invoke-last-command-fn) - (do - (print-commands nil container-map commands-map false) - (exit 0))) + (do + (print-commands nil container-map commands-map false) + ;; This is the ugly mixed case where its a group and a command; we present + ;; the group first then the command. + (when invoke-last-command-fn + (println) + (invoke-last-command-fn)) + (exit 0)) :let [possible-commands commands-map matchable-terms (keys possible-commands)] diff --git a/test/net/lewisship/cli_tools/messy_test.clj b/test/net/lewisship/cli_tools/messy_test.clj index 3a6309c..a6d7218 100644 --- a/test/net/lewisship/cli_tools/messy_test.clj +++ b/test/net/lewisship/cli_tools/messy_test.clj @@ -39,11 +39,21 @@ (dispatch "mess" "kiwi")))) (deftest help-for-messy-command-shows-command-help - (let [{:keys [status out]} (dispatch "mess" "-h")] - (is (= 0 status)) - (is (string/includes? out "Usage:")) - (is (string/includes? out "NAME")) - (is (not (string/includes? out "nested"))))) + (is (match? {:status 0 + :out-lines ["bigmess messy - Messy command and group at same time" + "" + "Commands:" + " nested: Command nested under messy group/command" + "" + "Usage: bigmess messy [OPTIONS] NAME" + "Messy command." + "" + "Options:" + " -h, --help This command summary" + "" + "Arguments:" + " NAME: Name to print"]} + (dispatch "mess" "-h")))) (comment