9.1.0 - option.conflicts not working
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.
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.)
Any idea when this might be released?
Hi @rpearce63 , likely within a week.
(Not a hard rule, but I prefer to wait a month between releases.)
Fixed in Commander v9.2.0
The update worked. Thanks.
% node commands.js claim -a -x OG
error: option '-a, --all' cannot be used with option '-x, --exact <name>'