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

Allow option to conflict with the negation of another option. #2175

Open
KAYounes opened this issue Apr 1, 2024 · 5 comments
Open

Allow option to conflict with the negation of another option. #2175

KAYounes opened this issue Apr 1, 2024 · 5 comments

Comments

@KAYounes
Copy link

KAYounes commented Apr 1, 2024

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.

@shadowspawn
Copy link
Collaborator

shadowspawn commented Apr 1, 2024

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

@KAYounes
Copy link
Author

KAYounes commented Apr 3, 2024

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?

@shadowspawn
Copy link
Collaborator

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.

@shadowspawn
Copy link
Collaborator

shadowspawn commented Apr 3, 2024

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?

@KAYounes
Copy link
Author

KAYounes commented Apr 5, 2024

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.

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

2 participants