Currently
It's nice that bb cli supports --no-foo:
(cli/parse-opts ["--foo"])
;; => {:foo true}
(cli/parse-opts ["--no-foo"])
;; => {:foo false}
(cli/parse-opts ["--no-foo"] {:spec {:foo {:coerce :boolean}}})
;; => {:foo false}
But what if foo is not a boolean?
When false is coercible, it doesn't fail...
(cli/parse-opts ["--no-foo"] {:spec {:foo {:coerce :symbol}}})
;; => {:foo false}
(cli/parse-opts ["--no-foo"] {:spec {:foo {:coerce :string}}})
;; => {:foo "false"}
(cli/parse-opts ["--no-foo"] {:spec {:foo {:coerce :keyword}}})
;; => {:foo :false}
But since this makes no sense, I'm thinking specifying --no-foo here merits an error.
We do get an error when false is not coercible...
(cli/parse-opts ["--no-foo"] {:spec {:foo {:coerce :long}}})
;; => Execution error (ExceptionInfo) at babashka.cli/->error-fn$fn (cli.cljc:263).
;; Invalid value for option --no-foo: cannot transform input "false" to long
But the error message is not the user-friendliest.
Proposal
Generate a helpful error message when --no- is applied to a non-boolean option.
For the :cause we could create a new :not-negatable or reuse the existing :coerce but with a better message: Cannot negate --foo.
Out of scope
I think the :negatable option is still fine as it is.
It only affects generated help.
If a developer slaps this on a non-boolean option, that's a developer error.
Currently
It's nice that bb cli supports
--no-foo:But what if foo is not a boolean?
When
falseis coercible, it doesn't fail...But since this makes no sense, I'm thinking specifying
--no-foohere merits an error.We do get an error when
falseis not coercible...But the error message is not the user-friendliest.
Proposal
Generate a helpful error message when
--no-is applied to a non-boolean option.For the
:causewe could create a new:not-negatableor reuse the existing:coercebut with a better message: Cannot negate --foo.Out of scope
I think the
:negatableoption is still fine as it is.It only affects generated help.
If a developer slaps this on a non-boolean option, that's a developer error.