diff --git a/CHANGES.md b/CHANGES.md index a0db0db..4a30b57 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,7 @@ +# 1.0.2 -- UNRELEASED + +* fix: Completions generation fails when tool options include extra tools.cli keys [#70](https://github.com/hlship/cli-tools/issues/70) + # 1.0.1 -- 14 Aug 2026 * fix: Use of `defcommand` can produce a number of spurious warnings with clj-kondo [#67](https://github.com/hlship/cli-tools/issues/67) diff --git a/src/net/lewisship/cli_tools/completions.clj b/src/net/lewisship/cli_tools/completions.clj index 26ef139..08a84e2 100644 --- a/src/net/lewisship/cli_tools/completions.clj +++ b/src/net/lewisship/cli_tools/completions.clj @@ -24,7 +24,7 @@ (string/replace s "'" "\\'")) (defn- to-opt - [short-option long-option summary] + [[short-option long-option summary]] (let [both (and long-option short-option) [long-option' option-name] (when long-option (string/split long-option #"\s+"))] @@ -51,8 +51,7 @@ (let [{:keys [fn]} command-map callable (requiring-resolve fn) {:keys [command-options]} (callable)] - (for [[short-option long-option summary] command-options] - (to-opt short-option long-option summary)))) + (map to-opt command-options))) (defn- extract-command [fn-prefix [command-name command-map]] @@ -88,7 +87,7 @@ (defn- print-tool [tool-name command-root extra-options] (let [prefix (str "_" tool-name) - options (map #(apply to-opt %) (concat extra-options impl/default-tool-options)) + options (map to-opt (concat extra-options impl/default-tool-options)) commands (->> command-root (keep #(extract-command prefix %)))] (selmer.util/without-escaping diff --git a/test/net/lewisship/cli_tools/completions_test.clj b/test/net/lewisship/cli_tools/completions_test.clj index c5aaa2c..d7f0028 100644 --- a/test/net/lewisship/cli_tools/completions_test.clj +++ b/test/net/lewisship/cli_tools/completions_test.clj @@ -57,5 +57,10 @@ (dispatch {:tool-name "options" :namespaces '[net.lewisship.cli-tools.completions] - :extra-tool-options [["-d" "--debug" "Enable debug mode"] - ["-o" "--output-path FILE" "Write output to file, not stdout"]]})))) + :extra-tool-options [["-d" "--debug" "Enable debug mode" + :id :debug] + ["-o" "--output-path FILE" "Write output to file, not stdout" + :id :output-path + :default "-" + :parse-fn identity + :validate [some? "Must be provided"]]]}))))