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
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ For breaking changes, check [here](#breaking-changes).

[Babashka CLI](https://github.com/babashka/cli): turn Clojure functions into CLIs!

## v0.8.65
## v0.8.66 (2025-07-12)

- [#122](https://github.com/babashka/cli/issues/122): introduce new
`:repeated-opts` option to enforce repeating the option for accepting multiple
values (e.g. `--foo 1 --foo 2` rather than `--foo 1 2`)

## v0.8.65 (2025-04-14)

- [#119](https://github.com/babashka/cli/issues/119): `format-table` now formats multiline cells appropriately
([@lread](https://github.com/lread))
Expand Down
6 changes: 4 additions & 2 deletions src/babashka/cli.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@
* `:validate` - a map of validator functions. See [validate](https://github.com/babashka/cli#validate).
* `:exec-args` - a map of default args. Will be overridden by args specified in `args`.
* `:no-keyword-opts` - `true`. Support only `--foo`-style opts (i.e. `:foo` will not work).
* `:repeated-opts` - `true`. Forces writing the option name for every value, e.g. `--foo a --foo b`, rather than `--foo a b`
* `:args->opts` - consume unparsed commands and args as options
* `:collect` - a map of collection fns. See [custom collection handling](https://github.com/babashka/cli#custom-collection-handling).

Expand Down Expand Up @@ -414,12 +415,12 @@
(let [k (if negative?
(keyword (str/replace (str k) ":no-" ""))
k)
next-args (cons (not negative?) #_"true" next-args)]
next-args (cons (not negative?) next-args)]
(recur (process-previous acc current-opt added collect-fn)
k added mode next-args
a->o)))
(recur (process-previous acc current-opt added collect-fn)
k added mode next-args
k nil mode next-args
a->o)))))))
(let [the-end? (or
(and (= :boolean coerce-opt)
Expand All @@ -428,6 +429,7 @@
(and (= added current-opt)
(or
(not collect-fn)
(:repeated-opts opts)
(contains? (::dispatch-tree-ignored-args opts) (first args)))))]
(if the-end?
(let [{new-args :args
Expand Down
9 changes: 7 additions & 2 deletions test/babashka/cli_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -647,5 +647,10 @@
{:dispatch ["dns" "get"],
:opts {:config ["config-dev.edn" "other.edn"]},
:args nil}
(cli/dispatch table ["--config" "config-dev.edn" "--config=other.edn" "dns" "get"]))))
)
(cli/dispatch table ["--config" "config-dev.edn" "--config=other.edn" "dns" "get"])))))

(deftest repeated-opts-test
(is (= {:opts {:foo [1 2]}}
(cli/parse-args ["--foo" "1" "--foo" "2"] {:repeated-opts true :spec {:foo {:coerce []}}})))
(is (= {:args ["2"], :opts {:foo [1]}}
(cli/parse-args ["--foo" "1" "2"] {:repeated-opts true :spec {:foo {:coerce []}}}))))
Loading