Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #106: multiple options before subcommand conflict with subcommand #107

Merged
merged 1 commit into from
Nov 15, 2024
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ For breaking changes, check [here](#breaking-changes).
## Unreleased

- Fix [#102](https://github.com/babashka/cli/issues/102): `format-table` correctly pads cells containing ANSI escape codes
- Fix [#106](https://github.com/babashka/cli/issues/106): Multiple options before subcommand conflict with subcommand

## v0.8.60 (2024-07-23)

Expand Down
6 changes: 4 additions & 2 deletions src/babashka/cli.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,9 @@
(not= arg "true")
(not= arg "false"))
(and (= added current-opt)
(not collect-fn)))]
(or
(not collect-fn)
(contains? (::dispatch-tree-ignored-args opts) (first args)))))]
(if the-end?
(let [{new-args :args
a->o :args->opts}
Expand Down Expand Up @@ -535,7 +537,7 @@
(fn [widths row]
(map max (map str-width row) widths)) (repeat 0) rows)
pad-row (fn [row]
(map (fn [width cell] (pad width cell)) widths row))]
(map pad widths row))]
(map pad-row rows)))

(defn format-table [{:keys [rows indent] :or {indent 2}}]
Expand Down
31 changes: 31 additions & 0 deletions test/babashka/cli_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -587,3 +587,34 @@
:spec {:x {:coerce :boolean}}}]
["foo"]
{:restrict true}))))

(deftest issue-106-test
(d/deflet
(def global-spec {:config {:desc "Config edn file to use"
:coerce []}
:verbose {:coerce :boolean}})
(def dns-spec {})
(def dns-get-spec {})
(def table
[{:cmds [] :fn identity :spec global-spec}
{:cmds ["dns"] :fn identity :spec dns-spec}
{:cmds ["dns" "get"] :fn identity :spec dns-get-spec}])
(is (submap?
{:dispatch ["dns"], :opts {:config ["config-dev.edn" "other.edn"]}, :args nil}
(cli/dispatch table ["--config" "config-dev.edn" "--config" "other.edn" "dns"])))
(is (submap?
{:dispatch ["dns" "get"],
:opts {:config ["config-dev.edn" "other.edn"]},
:args nil}
(cli/dispatch table ["--config" "config-dev.edn" "--config" "other.edn" "dns" "get"])))
(is (submap?
{:dispatch ["dns" "get"],
:opts {:config ["config-dev.edn" "other.edn"], :verbose true},
:args nil}
(cli/dispatch table ["--config" "config-dev.edn" "--verbose" "--config" "other.edn" "dns" "get"])))
(is (submap?
{:dispatch ["dns" "get"],
:opts {:config ["config-dev.edn" "other.edn"]},
:args nil}
(cli/dispatch table ["--config" "config-dev.edn" "--config=other.edn" "dns" "get"]))))
)
Loading