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

Proposals for on/off switch #691

Closed
ntkme opened this issue Sep 7, 2017 · 2 comments
Closed

Proposals for on/off switch #691

ntkme opened this issue Sep 7, 2017 · 2 comments

Comments

@ntkme
Copy link
Contributor

ntkme commented Sep 7, 2017

The justification for this has been discussed #108. I have working code but I'd like to open a discussion before opening a PR.

Proposal 1

program
  .version('0.0.1')
  .option('    --[no-]color', 'optionally turn on or off the color');

Proof of concept implementation:

https://github.com/ntkme/commander.js/compare/master...ntkme:optional-switch

Pros

  • Small overhead
  • Default value works as expected

Cons

  • No short flag

Proposal 2

program
  .version('0.0.1')
  .option('-c, --color', 'enable color')
  .option('-C, --no-color', 'disable color')

Proof of concept implementation:

https://github.com/ntkme/commander.js/compare/master...ntkme:boolean-switch

Pros

  • Short flag works fine

Cons

  • The proof of concept implementation has to take a look back at all previous options, which means:
    • Weak performance
    • Default value has to be set on the second option
    • Can be overcome by setting default values only when calling .parse() (breaking change, not a good idea)
@abetomo
Copy link
Collaborator

abetomo commented Sep 8, 2017

@ntkme Thank you.
I think that Proposal 1 is good.

@vanesyan What do you think?

@syberkitten
Copy link

syberkitten commented Nov 15, 2017

Hey Guys
It's so missing.... there are so many times I want to use a switch,
and right the way to achieve this is to use normal arguments adding them a value just to
make a switch.

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

No branches or pull requests

3 participants