-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Proposals for on/off switch #691
Copy link
Copy link
Closed
Labels
Description
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)
Reactions are currently unavailable