-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Adding negative option makes Commander.js to return "true" when option is not specified #979
Comments
There is special processing for When the feature was added long ago, it was assumed it would be used without the ordinary flag. There are currently issues with trying to use both |
@shadowspawn thank you for explanation. But is there a way to disable this special behavior for |
Short version: no. (Not that I am aware of.) |
See #795 for the new behaviour if it is accepted (which is likely). |
The existence of the negated option shouldn't make If we say "user can ask to make pizza without a cheese" it doesn't mean, that if she didn't ask it, we have to always make pizza with cheese. It's a twisted logic. The much better API would be:
With such approach, the developer don't have to define negated option specifically at all, instead, every option could be negated. I believe such API would be straightforward, intuitive and easy to work with. And if we really want to have a default value, then the developer should provide it, we shouldn't make this choice for her, e.g.: |
Totally agree, and as mentioned above, this will very likely be fixed in the next major version. Feel free to subscribe to #795. :) |
@usmonster great to hear that we are on the same page on this. Thank you for you contribution! Looking forward for this to be merged. |
This issue will be resolved when v3.0.0 is released. Available now as a prerelease. See #1001 |
Support for combined |
Hello!
I'm encountering yet another strange behavior of Commander.js.
When I add the following option:
command.option('--clean', 'cleans the destination build directory');
And then run my program this way:
program
, the Commander returnsclean
option asundefined
.However, when I add an additional negative option:
It starts to return
true
for theclean
option when executed the same as above instead of theundefined
.Why is that? I want the option to be always
undefined
if it's not specified via CLI.The text was updated successfully, but these errors were encountered: