Closed albertvaka closed 1 year ago
This is already how Option.Boolean
works;
import { Command, Option, runExit } from 'clipanion';
class Foo extends Command {
optionalFeature = Option.Boolean(`--my-optional-feature`, true);
async execute() {
console.log(this.optionalFeature);
return 0;
}
}
runExit([Foo]);
$ my-cli
true
$ my-cli --no-my-optional-feature
false
$ my-cli --my-optional-feature
true
I want my users to be able to disable certain behavior in my CLI, by passing
--no-<something>
.Currently I can do that by adding a boolean option, eg:
--no-my-optional-feature
and store that asnoMyOptionalFeature
boolean. But then in my code I have to do double negations:if (!noMyOptionalFeature) { enableOptionalFeature(); }
because my boolean istrue
when I don't want that feature enabled.It would be nice to have support for positive boolean arguments that default to
true
and that can be disabled by default by prefixing them withno-
. This way, also, if as a user I want to explicitly enable the optional feature I could also write--my-optional-feature
(without theno-
prefix) and that would also be a valid argument.