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

BUG: defining an option which includes no- makes the option true by default #1301

Closed
snitin315 opened this issue Jul 17, 2020 · 4 comments
Closed
Labels
bug Commander is not working as intended

Comments

@snitin315
Copy link

snitin315 commented Jul 17, 2020

Current Behavior -
If we define an option whose name contains no- for e.g. module-no-parse, it makes the option true by default.

Expected Behavior -
It is supposed to do this only for flags with leading no- as mentioned in docs. https://github.com/tj/commander.js/#other-option-types-negatable-boolean-and-flagvalue

You can specify a boolean option long name with a leading no- to set the option value to false when used. Defined alone this also makes the option true by default.

Steps to reproduce -
Define an option whose name includes no- e.g. module-no-parse.
Check its default value in the parser.
Screenshot at 2020-07-16 20-28-38

Addition Info
Bug found via webpack/webpack-cli#1679

@snitin315
Copy link
Author

I think the bug is here -

this.negate = flags.indexOf('-no-') !== -1;

@snitin315
Copy link
Author

it should be this.negate = flags.indexOf('--no-') !== -1;

@shadowspawn shadowspawn added the bug Commander is not working as intended label Jul 17, 2020
@shadowspawn
Copy link
Collaborator

Reproduced.

I did a bit of digging to see how the code has evolved. Back in Commander v2.3.0, the -no- support was undocumented and simplistic, and looked for the -no- anywhere in the long option flag. The handling of no- got a big rework in #795 and (mostly) switched to --no- being just at the start of the option flag. The initial test didn't get changed though, and hence the current bug!

@shadowspawn shadowspawn added the pending release Merged into a branch for a future release, but not released yet label Jul 18, 2020
shadowspawn added a commit to shadowspawn/commander.js that referenced this issue Jul 18, 2020
Co-author: snitin315@gmail.com
shadowspawn added a commit that referenced this issue Jul 19, 2020
Co-author: snitin315@gmail.com
@shadowspawn
Copy link
Collaborator

Fixed in Commander v6.0.0 which has been released: https://github.com/tj/commander.js/releases/tag/v6.0.0

@shadowspawn shadowspawn removed the pending release Merged into a branch for a future release, but not released yet label Jul 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Commander is not working as intended
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants