I'm using commander.js to parse the command line args and I'm trying to collect an optional param that can appear multiple times and it always returns the options I set plus the default one.
function collect (val, memo) {
memo.push(val);
return memo;
}
program
.command('run <param>')
.action(function run(param, options) {
console.log(param);
console.log(options.parent.config);
});
program
.option('-c, --config <path>', 'Config', collect, ["/path/to/default"])
.parse(process.argv);
When I call the script like this:
index.js run some -c "/some/path" -c "/other/path"
It prints:
[ '/path/to/default', '/some/path', '/other/path' ]
But it should only print:
['/some/path', '/other/path' ]`
When I call it without the -c
param it works correctly, printing the array with the default value. How can I fix this?