-
Notifications
You must be signed in to change notification settings - Fork 105
Open
Labels
Description
As in #112, I was surprised to find that parsing a flag with a type when the argument is omitted does not error, instead returning null
. That issue points to the wiki, which says I should do the validation myself. Fair enough.
Unfortunately, it is impossible to do the validation myself when the flag is specified as multiple
, because the output for --flag arg --flag
is identical to the output to the output for --flag arg
.
That is:
const commandLineArgs = require('command-line-args');
const options = [{
name: 'flag',
type: String,
multiple: true,
defaultValue: 'default',
}];
console.log(commandLineArgs(options));
invoked with
node cli-args.js --flag arg --flag
and with
node cli-args.js --flag arg
both give exactly the same output,
{ flag: [ 'arg' ] }
So it is not actually possible to check whether the user has passed a flag without specifying its (required) argument.
I was hoping that it would at least put the default
value in the output array (or null
, if not specified), which I could check for.