commander.js
commander.js copied to clipboard
Allow option to conflict with the negation of another option.
A simple example will make things clear
program
.addOption(new Option("-c, --cheese"))
.addOption(new Option("-no-c, --no-cheese"))
.addOption(new Option("-t, --cheese-type <type>").conflicts("noCheese"))
What I am trying achieve is, the option of --no-cheese should not be passed with --cheese-type.
Currently, this is allowed since noCheese
is not seen as a stand alone option, instead it is mapped to cheese
.
There is not a separate option name for --no-cheese
, both it and --cheese
affect the option key cheese
.
Try the behaviour with:
.addOption(new Option("-t, --cheese-type <type>").conflicts("cheese"))
Example file: https://github.com/tj/commander.js/blob/master/examples/options-conflicts.js
There is not a separate option name for
--no-cheese
, both it and--cheese
affect the option keycheese
.Try the behaviour with:
.addOption(new Option("-t, --cheese-type <type>").conflicts("cheese"))
Example file: https://github.com/tj/commander.js/blob/master/examples/options-conflicts.js
I know, I was trying to request a feature. Not sure if this was the right way to do so. Could you guide me please?
I have marked this issue as a feature request. It got left out of the implementation because it didn't fit into the pattern of specifying the internal option name, and was difficult to implement.
- https://github.com/tj/commander.js/pull/1678#issuecomment-1014230704
- https://github.com/tj/commander.js/pull/1678#issuecomment-1034502483
Could you guide me please?
What would be useful is a real-world example. I understand you want to add a conflict with just the negative option of a dual positive/negative pair, like --no-cheese
from the examples. What options would you use this for in your actual application?
What options would you use this for in your actual application?
For example, if I have two options --create-css-file
and --css-file-name <name>
. Now, if the user does --no--create-css-file --css-file-name styles
those are two conflicting options.
Hope this is a clear example.