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

9.1.0 - option.conflicts not working #1710

Closed
rpearce63 opened this issue Mar 24, 2022 · 5 comments
Closed

9.1.0 - option.conflicts not working #1710

rpearce63 opened this issue Mar 24, 2022 · 5 comments
Labels
bug Commander is not working as intended

Comments

@rpearce63
Copy link

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.

@shadowspawn shadowspawn added the bug Commander is not working as intended label Mar 24, 2022
@shadowspawn
Copy link
Collaborator

Thanks for the example.

This is a bug. When a subcommand is used, the conflicts are only being checked on the subcommand and not the program.

(In the code it looks right with _checkForConflictingOptions in same place as _checkForMissingMandatoryOptions, but that second call walks up the stack.)

@shadowspawn shadowspawn added the pending release Merged into a branch for a future release, but not released yet label Mar 25, 2022
@rpearce63
Copy link
Author

Any idea when this might be released?

@shadowspawn
Copy link
Collaborator

Hi @rpearce63 , likely within a week.

(Not a hard rule, but I prefer to wait a month between releases.)

@shadowspawn shadowspawn removed the pending release Merged into a branch for a future release, but not released yet label Apr 15, 2022
@shadowspawn
Copy link
Collaborator

Fixed in Commander v9.2.0

@rpearce63
Copy link
Author

The update worked. Thanks.

 % node commands.js claim -a -x OG
error: option '-a, --all' cannot be used with option '-x, --exact <name>'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Commander is not working as intended
Projects
None yet
Development

No branches or pull requests

2 participants