commander.js icon indicating copy to clipboard operation
commander.js copied to clipboard

Allow option to conflict with the negation of another option.

Open KAYounes opened this issue 10 months ago • 5 comments

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.

KAYounes avatar Apr 01 '24 08:04 KAYounes

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

shadowspawn avatar Apr 01 '24 22:04 shadowspawn

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

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?

KAYounes avatar Apr 03 '24 09:04 KAYounes

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

shadowspawn avatar Apr 03 '24 20:04 shadowspawn

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?

shadowspawn avatar Apr 03 '24 20:04 shadowspawn

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.

KAYounes avatar Apr 05 '24 13:04 KAYounes