fix: eatNargs() for 'opt.narg === 0' and boolean typed options (#188) · yargs/yargs-parser@c5a1db0

@@ -173,13 +173,14 @@ function parse (args, opts) {

173173

key = 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) {

177178

i = eatNargs(i, key, args)

178179

// array format = '--foo a b c'

179180

} else if (checkAllAliases(key, flags.arrays) && args.length > i + 1) {

180181

i = eatArray(i, key, args)

181182

} else {

182-

next = flags.nargs[key] === 0 ? undefined : args[i + 1]

183+

next = args[i + 1]

183184184185

if (next !== undefined && (!next.match(/^-/) ||

185186

next.match(negative)) &&

@@ -266,7 +267,8 @@ function parse (args, opts) {

266267267268

if (!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) {

270272

i = 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) {

347349

var ii

348350

const 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.

352359

var available = 0

@@ -747,7 +754,7 @@ function parse (args, opts) {

747754

var toCheck = [].concat(flags.aliases[key] || [], key)

748755749756

toCheck.forEach(function (key) {

750-

if (flag[key]) isSet = flag[key]

757+

if (flag.hasOwnProperty(key)) isSet = flag[key]

751758

})

752759753760

return isSet