Skip to content

Commit a28ac42

Browse files
committed
Fix #126: wonky behavior with - value
1 parent 41ec9c5 commit a28ac42

3 files changed

Lines changed: 9 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ For breaking changes, check [here](#breaking-changes).
44

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

7+
## Unreleased
8+
9+
- [#126](https://github.com/babashka/cli/issues/126): `-` value accidentally parsed as option, e.g. `--file -`
10+
711
## v0.8.66 (2025-07-12)
812

913
- [#122](https://github.com/babashka/cli/issues/122): introduce new

src/babashka/cli.cljc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
(try
8686
(let [s ^String s
8787
fst-char (first-char s)
88-
#?@(:clj [leading-num-char (if (= fst-char \-)
88+
#?@(:clj [leading-num-char (if (= \- fst-char)
8989
(second-char s)
9090
fst-char)])]
9191
(cond (or (= "true" s)
@@ -239,6 +239,7 @@
239239
snd-char (second-char arg)
240240
hyphen-opt? (and (not= :keywords mode)
241241
(= \- fst-char)
242+
(> (count arg) 1)
242243
(let [k (keyword (subs arg 1))]
243244
(or
244245
(contains? known-keys k)

test/babashka/cli_test.cljc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,3 +654,6 @@
654654
(cli/parse-args ["--foo" "1" "--foo" "2"] {:repeated-opts true :spec {:foo {:coerce []}}})))
655655
(is (= {:args ["2"], :opts {:foo [1]}}
656656
(cli/parse-args ["--foo" "1" "2"] {:repeated-opts true :spec {:foo {:coerce []}}}))))
657+
658+
(deftest issue-126-test
659+
(is (= {:file "-"} (cli/parse-opts ["--file" "-"]))))

0 commit comments

Comments
 (0)