File tree Expand file tree Collapse file tree 6 files changed +30
-24
lines changed
test/net/lewisship/cli_tools Expand file tree Collapse file tree 6 files changed +30
-24
lines changed Original file line number Diff line number Diff line change 22
33* BREAKING CHANGES*
44
5- * JDK 17 is now required when using Clojure
65* Groups are now defined in the options passed to ` net.lewisship.cli-tools/dispatch ` , not in
76 namespace metadata
87* Command names are matched as prefixes (not substrings)
Original file line number Diff line number Diff line change @@ -57,7 +57,6 @@ Documentation starts with [the overview](doc/overview.md).
5757## Compatibility
5858
5959` cli-tools ` is compatible with Clojure 1.11 and above, and w/ Babashka.
60- For Clojure, it requires JDK 17 or above.
6160
6261## License
6362
Original file line number Diff line number Diff line change 170170 ; ; it can also be a map with key :options
171171 test-mode?# (impl/command-map? args#)
172172 command-spec# ~(select-keys parsed-interface parse-cli-keys)]
173+ ; ; introspection mode is used primarily by completions; it invokes the function with no arguments
174+ ; ; (but with the flag on) and the command-spec is returned, from which completions are generated.
173175 (if impl/*introspection-mode*
174176 command-spec#
175- (let [~command-map-symbol (cond
176- test-mode?#
177+ (let [~command-map-symbol (if test-mode?#
177178 {:options (first args#)}
178-
179- impl/*introspection-mode*
180- command-spec#
181-
182- :else
183179 (impl/parse-cli ~command-name'
184180 ~docstring
185181 args#
Original file line number Diff line number Diff line change 99 [clj-commons.ansi :refer [perr]]
1010 #?(:bb [babashka.classpath :as cp]))
1111 (:import (java.io File)
12- (java.util HexFormat)
1312 (java.nio ByteBuffer)
1413 (java.security MessageDigest)))
1514
5958 ; ; Adding or removing a file (even if no other files are touched) will change the digest.
6059 (update-digest-recursively digest f))))
6160
62- (defn- hex-string
63- [^bytes input ]
64- ( -> ( HexFormat/of )
65- ( .formatHex input )))
61+ (defn- hex-string [^bytes input]
62+ ( let [sb ( StringBuilder. ) ]
63+ ( run! #( .append sb ( format " %X " %)) input )
64+ ( str sb )))
6665
6766(defn classpath-digest
6867 " Passed the tool options, return a hex string of the SHA-1 digest of the files from the classpath and
Original file line number Diff line number Diff line change 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)]
Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments