commander.option('-I --increment [value]', 'The interval increment', parseInt)
commander.increment // works if '-I 2'
commander.option('-I --increment [value]', 'The interval increment', parseInt, 1)
commander.increment // gives NaN if '-I 2'
Seems like a bug or do I get it wrong?
commander.option('-I --increment [value]', 'The interval increment', str => parseInt(str), 1)
this works though
Did you try debugging it? My first guess would be that it's passing two params (input and default), which ends up calling parseInt with an invalid radix (e.g. parseInt(2, 1) // NaN)
BTW this is the behavior across options which allows you to do things like collections:
commander.option('-f, --foo <val>', 'Add values to foo', collect, []);
function collect(val, collection) {
collection.push(val);
return collection;
}
Which can be invoked: program --foo=hi --foo=bye and yields ['hi', 'bye']
@bfricka yes you made a right guess 馃憤
would be better to improve the doc :)
Most helpful comment
BTW this is the behavior across options which allows you to do things like collections:
Which can be invoked:
program --foo=hi --foo=byeand yields['hi', 'bye']