fix: eatNargs() for 'opt.narg === 0' and boolean typed options (#188) · yargs/yargs-parser@c5a1db0
@@ -173,13 +173,14 @@ function parse (args, opts) {
173173key = arg.match(/^--?(.+)/)[1]
174174175175// nargs format = '--foo a b c'
176-if (checkAllAliases(key, flags.nargs)) {
176+// should be truthy even if: flags.nargs[key] === 0
177+if (checkAllAliases(key, flags.nargs) !== false) {
177178i = eatNargs(i, key, args)
178179// array format = '--foo a b c'
179180} else if (checkAllAliases(key, flags.arrays) && args.length > i + 1) {
180181i = eatArray(i, key, args)
181182} else {
182-next = flags.nargs[key] === 0 ? undefined : args[i + 1]
183+next = args[i + 1]
183184184185if (next !== undefined && (!next.match(/^-/) ||
185186next.match(negative)) &&
@@ -266,7 +267,8 @@ function parse (args, opts) {
266267267268if (!broken && key !== '-') {
268269// nargs format = '-f a b c'
269-if (checkAllAliases(key, flags.nargs)) {
270+// should be truthy even if: flags.nargs[key] === 0
271+if (checkAllAliases(key, flags.nargs) !== false) {
270272i = eatNargs(i, key, args)
271273// array format = '-f a b c'
272274} else if (checkAllAliases(key, flags.arrays) && args.length > i + 1) {
@@ -347,6 +349,11 @@ function parse (args, opts) {
347349var ii
348350const toEat = checkAllAliases(key, flags.nargs)
349351352+if (toEat === 0) {
353+setArg(key, defaultValue(key))
354+return i
355+}
356+350357// nargs will not consume flag arguments, e.g., -abc, --foo,
351358// and terminates when one is observed.
352359var available = 0
@@ -747,7 +754,7 @@ function parse (args, opts) {
747754var toCheck = [].concat(flags.aliases[key] || [], key)
748755749756toCheck.forEach(function (key) {
750-if (flag[key]) isSet = flag[key]
757+if (flag.hasOwnProperty(key)) isSet = flag[key]
751758})
752759753760return isSet