-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
I'd like to allow any and all options, because my application has plugins that can support their own options that my code itself doesn't know about. I just want to pass on all options as given to plugins, and they pick the ones they know about (hope this makes sense so far).
Sadly allowUnknownOption doesn't work as I expected, and I was wondering if this is a bug, or am I missing something?
const program = require('commander');
program
.version('1.0.0')
.allowUnknownOption()
.option('-i, --input [input]', 'input file')
.option('-o, --output [output]', 'output file')
.parse(process.argv);
console.log(program);When I run this with node test.js --foo bar then I would expect that program.args would contain the foo option with the bar value, but instead program.args is empty.
Only when I run the script like node test.js foo bar, then program.args contains two values. So it seems that unknown options can't be supplied with the -- prefix, which means they don't fit well with the "regular" options that my application itself supports, and that plugins can't really expect to get key/value pairs?
At the moment it seems like plugins would need to re-process the program.rawArg themselves using Commander with their own explicitly configured options, which is a shame to explain to my plugin authors.