From 98b3728c3b5666a2ea5c5e19a56a694a69b58df2 Mon Sep 17 00:00:00 2001 From: Michiel Borkent Date: Mon, 18 Mar 2024 11:48:16 +0100 Subject: [PATCH] Fix #91: keyword options and hyphen options should not mix --- CHANGELOG.md | 4 ++++ src/babashka/cli.cljc | 3 ++- test/babashka/cli_test.cljc | 4 ++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 300a26d..cdbc991 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 + +- Fix #91: keyword options and hyphen options should not mix + ## v0.8.58 (2024-03-12) Fix [#89](https://github.com/babashka/cli/issues/89): long option never represents alias diff --git a/src/babashka/cli.cljc b/src/babashka/cli.cljc index d907bc3..bfcafa2 100644 --- a/src/babashka/cli.cljc +++ b/src/babashka/cli.cljc @@ -235,7 +235,8 @@ (defn- parse-key [arg mode current-opt coerce-opt added] (let [fst-char (first-char arg) snd-char (second-char arg) - hyphen-opt? (and (= fst-char \-) + hyphen-opt? (and (not= :keywords mode) + (= fst-char \-) (not (number-char? snd-char))) mode (or mode (when hyphen-opt? :hyphens)) fst-colon? (= \: fst-char) diff --git a/test/babashka/cli_test.cljc b/test/babashka/cli_test.cljc index bf1459f..6d12b6c 100644 --- a/test/babashka/cli_test.cljc +++ b/test/babashka/cli_test.cljc @@ -548,3 +548,7 @@ (deftest issue-89-alias-only-for-short-opt (is (= {:f "dude"} (cli/parse-opts ["--f" "dude"] {:spec {:foo {:alias :f}}})))) + +(deftest issue-91-keyword-mode-overrides-hypens-mode + (is (= {:args ["--baz"], :opts {:foo 1}} + (cli/parse-args [":foo" 1 "--baz"] {}))))