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

feat: support mix of required and conflicting options #1855

Closed
sagargurtu opened this issue Mar 21, 2023 · 2 comments
Closed

feat: support mix of required and conflicting options #1855

sagargurtu opened this issue Mar 21, 2023 · 2 comments

Comments

@sagargurtu
Copy link

Current Behavior

program
  .addOption(new Option('-p, --port <number>', 'port number').makeOptionMandatory())
  .addOption(new Option('--disable-server', 'disables the server').conflicts('port'))

In the above example, if both --port and --disable-server are provided, it shows conflicting error as expected. However, if only --disable-server is provided, it throws an error that says --port was not specified.

program
  .addOption(new Option('-p, --port <number>', 'port number'))
  .addOption(new Option('--disable-server', 'disables the server').conflicts('port'))

If --port is not marked as mandatory, the program runs if neither option is provided.

Desired Behavior

A way to specify either of two conflicting options as mandatory. In the above example, --port should be mandatory only if --disable-server is not provided.

  • If both --port and --disable-server are provided, it should show conflicting error as expected.
  • If only --disable-server is provided, it should not throw any error.
  • If only --port is provided, it should not throw any error.
  • If neither option is provided, it should throw an error that says --port was not specified.
@shadowspawn
Copy link
Collaborator

I researched some constraints offered by other libraries a while ago: #1802 (comment)

I think prior art for what you describe are:

  • Oclif has exactlyOne
  • Python argparse has add_mutually_exclusive_group(required=True)

(In general I am not planning to add more constraints, unless there is sufficient interest.)

@shadowspawn
Copy link
Collaborator

This issue has not had much activity in six months. It isn't likely to get acted on due to this report.

Thanks for the suggestion. It is quite a lot of work robustly supporting option interactions in Commander. There are lots of possible constraints, and not many requests. Not planning to add more without clarity that it is solving a problem that enough people would benefit from.

Feel free to open a new issue if it comes up again, with new information and renewed interest.

Thank you for your contributions.

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