diff --git a/index.js b/index.js index 11eac1e5..1b8e1582 100644 --- a/index.js +++ b/index.js @@ -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)) && @@ -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 @@ -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