Skip to content

feat: support mix of required and conflicting options #1855

@sagargurtu

Description

@sagargurtu

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.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions