diff --git a/CHANGELOG.md b/CHANGELOG.md index 211a3d9..7653110 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ For breaking changes, check [here](#breaking-changes). [Babashka CLI](https://github.com/babashka/cli): turn Clojure functions into CLIs! +## Unreleased + +- [#126](https://github.com/babashka/cli/issues/126): `-` value accidentally parsed as option, e.g. `--file -` + ## v0.8.66 (2025-07-12) - [#122](https://github.com/babashka/cli/issues/122): introduce new diff --git a/src/babashka/cli.cljc b/src/babashka/cli.cljc index 04288f0..e36af4f 100644 --- a/src/babashka/cli.cljc +++ b/src/babashka/cli.cljc @@ -85,7 +85,7 @@ (try (let [s ^String s fst-char (first-char s) - #?@(:clj [leading-num-char (if (= fst-char \-) + #?@(:clj [leading-num-char (if (= \- fst-char) (second-char s) fst-char)])] (cond (or (= "true" s) @@ -239,6 +239,7 @@ snd-char (second-char arg) hyphen-opt? (and (not= :keywords mode) (= \- fst-char) + (> (count arg) 1) (let [k (keyword (subs arg 1))] (or (contains? known-keys k) diff --git a/test/babashka/cli_test.cljc b/test/babashka/cli_test.cljc index e8932d2..b3dd800 100644 --- a/test/babashka/cli_test.cljc +++ b/test/babashka/cli_test.cljc @@ -654,3 +654,7 @@ (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 []}}})))) + +(deftest issue-126-test + (is (= {:file "-"} (cli/parse-opts ["--file" "-"]))) + (is (= {:file "-"} (cli/parse-opts ["-"] {:args->opts [:file]}))))