Skip to content

Commit 1ef8e44

Browse files
committed
fix checkAllAliases() for nargs === 0
fix eatNargs() for boolean's
1 parent 31c204b commit 1ef8e44

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

index.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,13 +173,14 @@ function parse (args, opts) {
173173
key = arg.match(/^--?(.+)/)[1]
174174

175175
// 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]
183184

184185
if (next !== undefined && (!next.match(/^-/) ||
185186
next.match(negative)) &&
@@ -347,6 +348,11 @@ function parse (args, opts) {
347348
var ii
348349
const toEat = checkAllAliases(key, flags.nargs)
349350

351+
if (toEat === 0 && checkAllAliases(key, flags.bools)) {
352+
setArg(key, true)
353+
return i
354+
}
355+
350356
// nargs will not consume flag arguments, e.g., -abc, --foo,
351357
// and terminates when one is observed.
352358
var available = 0
@@ -747,7 +753,7 @@ function parse (args, opts) {
747753
var toCheck = [].concat(flags.aliases[key] || [], key)
748754

749755
toCheck.forEach(function (key) {
750-
if (flag[key]) isSet = flag[key]
756+
if (flag.hasOwnProperty(key)) isSet = flag[key]
751757
})
752758

753759
return isSet

0 commit comments

Comments
 (0)