Skip to content

Commit

Permalink
fix checkAllAliases() for nargs === 0
Browse files Browse the repository at this point in the history
fix eatNargs() for boolean's
  • Loading branch information
juergba committed Jul 16, 2019
1 parent 31c204b commit 1ef8e44
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,14 @@ function parse (args, opts) {
key = arg.match(/^--?(.+)/)[1]

// nargs format = '--foo a b c'
if (checkAllAliases(key, flags.nargs)) {
// should be truthy even if: flags.nargs[key] === 0
if (checkAllAliases(key, flags.nargs) !== false) {
i = eatNargs(i, key, args)
// array format = '--foo a b c'
} else if (checkAllAliases(key, flags.arrays) && args.length > i + 1) {
i = eatArray(i, key, args)
} else {
next = flags.nargs[key] === 0 ? undefined : args[i + 1]
next = args[i + 1]

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

if (toEat === 0 && checkAllAliases(key, flags.bools)) {
setArg(key, true)
return i
}

// nargs will not consume flag arguments, e.g., -abc, --foo,
// and terminates when one is observed.
var available = 0
Expand Down Expand Up @@ -747,7 +753,7 @@ function parse (args, opts) {
var toCheck = [].concat(flags.aliases[key] || [], key)

toCheck.forEach(function (key) {
if (flag[key]) isSet = flag[key]
if (flag.hasOwnProperty(key)) isSet = flag[key]
})

return isSet
Expand Down

0 comments on commit 1ef8e44

Please sign in to comment.