Skip to content

9.1.0 - option.conflicts not working #1710

@rpearce63

Description

@rpearce63

I'm trying to use the option conflicts configuration, but it doesn't appear to catch the conflicts.

const { program, Option } = require("commander");

const handleAction = (command) => {
  const options = program.opts();
  //options.exact && (options.wild || options.all) && console.log("conflict");
  console.log(
    `${command.name()} with options ${JSON.stringify(program.opts())}`
  );
};
//Global options
program
  .addOption(
    new Option("-a, --all", "all wallets").conflicts(["exact", "wild"])
  )
  .addOption(
    new Option("-x, --exact <name>", "exact wallet name").conflicts([
      "all",
      "wild",
    ])
  )
  .addOption(
    new Option("-w, --wild <partial>", "wild card").conflicts(["all", "exact"])
  )
  .option("-p, --password <password>");

//Sub commands
program.command("claim").action((options, command) => {
  handleAction(command);
});

program.parse();

When I run with:
node commands.js claim -a -x OG

The result is:
claim with options {"all":true,"exact":"OG"}

Have I configured it incorrectly? Also tried specifying just the short names. Same result.

Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugCommander is not working as intended

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions