Skip to content

Commit

Permalink
Fix #82: prefer alias over composite option (#83)
Browse files Browse the repository at this point in the history
  • Loading branch information
borkdude authored Feb 22, 2024
1 parent 8abef05 commit 7c5b207
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ For breaking changes, check [here](#breaking-changes).

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

## Unreleased

Fix [#82](https://github.com/babashka/cli/issues/82): prefer alias over composite option

## v0.8.56 (2024-02-13)

- Add `:opts` to `:error-fn` input
Expand Down
5 changes: 3 additions & 2 deletions src/babashka/cli.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,8 @@
(str/split kname #"=")
[kname])
raw-k (keyword kname)
k (get aliases raw-k raw-k)]
alias (get aliases raw-k)
k (or alias raw-k)]
(if arg-val
(recur (process-previous acc current-opt added collect-fn)
k nil mode (cons arg-val (rest args)) a->o)
Expand All @@ -390,7 +391,7 @@
(empty? next-args)
negative?)
;; implicit true
(if composite-opt
(if (and (not alias) composite-opt)
(let [chars (name k)
args (mapcat (fn [char]
[(str "-" char) true])
Expand Down
5 changes: 5 additions & 0 deletions test/babashka/cli_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -540,3 +540,8 @@
:exec-args {:dude [:baz]}})))
(is (= {:foo [:bar]} (cli/parse-opts ["--foo" ":bar"] {:coerce {:foo []}
:exec-args {:foo [:baz]}}))))

(deftest issue-82-alias-preference
(is (= {:opts {:verbose2 true}}
(cli/parse-args ["-vv"] {:spec {:verbose1 {:alias :v}
:verbose2 {:alias :vv}}}))))

0 comments on commit 7c5b207

Please sign in to comment.