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

Refactor option value processing to improve maintainability and fix bugs #1648

Closed
shadowspawn opened this issue Dec 7, 2021 · 3 comments
Closed
Labels
bug Commander is not working as intended

Comments

@shadowspawn
Copy link
Collaborator

shadowspawn commented Dec 7, 2021

There is some subtle code in addOption which is hard to make sense of, and has some bugs. If is solid on options used once on command line, but from code inspection I was able to reproduce some logic errors affecting repeated options for boolean with a non-boolean default value (bit obscure!) and optional options.

The problems have been present for a long time. I was able to reproduce with v2.20.0 and traced code back to at least v1.1.0. The issues have not been generating reports, and the motivation for changing the code is as much to make the code easier to work on as to improve the behaviour.

addOption(option) {

@shadowspawn
Copy link
Collaborator Author

Example bug 1

program.option('-f, --flag', 'boolean option with a non-boolean default', 'flag seen')
program.parse(process.argv);
console.log(program.opts());
% node bug1.js -f
{ flag: 'flag seen' }
defaults % node bug1.js -f -f
{ flag: undefined }

@shadowspawn
Copy link
Collaborator Author

Example bug 2

program.option('-o, --optional [value]')
program.parse(process.argv);
console.log(program.opts());
defaults % node bug2 -o
{ optional: true }
defaults % node bug2 -o -o foo
{ optional: 'foo' }
defaults % node bug2 -o -o foo -o
{ optional: 'foo' }

@shadowspawn shadowspawn self-assigned this Dec 7, 2021
@shadowspawn shadowspawn added the bug Commander is not working as intended label Dec 7, 2021
@shadowspawn shadowspawn added the pending release Merged into a branch for a future release, but not released yet label Dec 21, 2021
@shadowspawn shadowspawn added this to the Commander v9.0.0 milestone Dec 21, 2021
@shadowspawn shadowspawn removed their assignment Dec 25, 2021
@shadowspawn shadowspawn removed the pending release Merged into a branch for a future release, but not released yet label Jan 29, 2022
@shadowspawn
Copy link
Collaborator Author

Commander v9 has been released.

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

No branches or pull requests

1 participant