Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #98: internal options should not interfere with :restrict #99

Merged
merged 1 commit into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}))))
Loading