tj / commander.js

node.js command-line interfaces made easy
MIT License
26.38k stars 1.69k forks source link

Enhancement: Handle syntax --[no-]cheese #2213

Open fodil-a-mindflow opened 2 weeks ago

fodil-a-mindflow commented 2 weeks ago

Hello,

I hope you're doing well! I just wanted to say that your library is fantastic. While working with it, I discovered that to create flags for both yes and no, I need to declare each one separately.

I was wondering if you might consider an enhancement to the syntax, such as using [no-], to automatically generate both commands with true/false values. 😃

I'd be happy to contribute by submitting a PR for this feature if you're interested.

Have a great day!

shadowspawn commented 1 week ago

Not sure quite what you have in mind. Would you see one option or two in the help?

For some historical background, the original support for a negated option (e.g. --no-cheese) was for a stand-alone option and it did not work as part of a yes/no pair of options.

Support was added in #795 to allow a yes/no pair of options to work nicely together, and extended in in #987 and #1652 for defaults and presets.

Now that we have a solid implementation, I am reluctant to add support for a single-option supporting both yes/no as an alternative way of implementing the same behaviour (#1355) without some compelling need or a lot of up-votes.

If you were thinking of an author shortcut for creating the pair of options with a single call, I think you could implement that with an override to Command.