Skip to content

Commit

Permalink
Fix #98: internal options should not interfere with :restrict (#99)
Browse files Browse the repository at this point in the history
  • Loading branch information
borkdude authored May 8, 2024
1 parent dcdece0 commit 4c76124
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
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 [#98](https://github.com/babashka/cli/issues/98): internal options should not interfere with :restrict

## v0.8.59 (2024-04-30)

- Fix [#96](https://github.com/babashka/cli/issues/96): prevent false defaults from being removed/ignored
Expand Down
3 changes: 2 additions & 1 deletion src/babashka/cli.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,8 @@
opts)]
(when restrict
(doseq [k (keys opts)]
(when-not (contains? restrict k)
(when (and (not (contains? restrict k))
(not= (namespace k) "babashka.cli"))
(error-fn {:cause :restrict
:msg (str "Unknown option: " k)
:restrict restrict
Expand Down
14 changes: 14 additions & 0 deletions test/babashka/cli_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -558,3 +558,17 @@
(deftest issue-91-keyword-mode-overrides-hypens-mode
(is (= {:args ["--baz"], :opts {:foo 1}}
(cli/parse-args [":foo" 1 "--baz"] {}))))

(deftest issue-98-dispatch+restrict-test
(is (thrown? Exception
(cli/dispatch [{:cmds ["foo"]
:fn identity
:spec {:x {:coerce :boolean}}}]
["foo" "--y"]
{:restrict true})))
(is (= {:dispatch ["foo"], :opts {}, :args nil}
(cli/dispatch [{:cmds ["foo"]
:fn identity
:spec {:x {:coerce :boolean}}}]
["foo"]
{:restrict true}))))

0 comments on commit 4c76124

Please sign in to comment.