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
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
7 changes: 3 additions & 4 deletions src/net/lewisship/cli_tools/completions.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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+"))]
Expand All @@ -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]]
Expand Down Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions test/net/lewisship/cli_tools/completions_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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"]]]}))))