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

Option callback is not called if optional value is not defined #116

Closed
kirbysayshi opened this issue Dec 31, 2012 · 2 comments
Closed

Option callback is not called if optional value is not defined #116

kirbysayshi opened this issue Dec 31, 2012 · 2 comments

Comments

@kirbysayshi
Copy link

Hopefully the title isn't too confusing :)

I have an option

.option('-c, --chart [columns]', 'Add columns', splitOrDefault, false)
  • If --chart is not present, I would want the value to be false.
  • If it is present, but [columns] are not, I want to default it to something like ['col1', 'col2'].
  • If something like --chart col1,col2,col3 is passed, I want those values to take precedence.

Unfortunately, the option value callback (splitOrDefault above) is not called if the value is undefined, and thus I cannot check for --chart being defined but not [columns], and it's just defaulted to false.

Given line 332, I get that this callback behavior is intended, but wanted to discuss before submitting a PR.

I may be asking for too much from commander, or there might be a simpler way... is this possible?

@abetomo
Copy link
Collaborator

abetomo commented Mar 16, 2018

Closing due to possible answer suggested and no response registered. Feel free to comment and we can re-open in case this issue persisted.

@shadowspawn
Copy link
Collaborator

Options with optional arguments and a default value were broken before Commander 9. This will be possible with proposed changes in #1652

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants