@@ -173,13 +173,14 @@ function parse (args, opts) {
173
173
key = arg . match ( / ^ - - ? ( .+ ) / ) [ 1 ]
174
174
175
175
// 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 ) {
177
178
i = eatNargs ( i , key , args )
178
179
// array format = '--foo a b c'
179
180
} else if ( checkAllAliases ( key , flags . arrays ) && args . length > i + 1 ) {
180
181
i = eatArray ( i , key , args )
181
182
} else {
182
- next = flags . nargs [ key ] === 0 ? undefined : args [ i + 1 ]
183
+ next = args [ i + 1 ]
183
184
184
185
if ( next !== undefined && ( ! next . match ( / ^ - / ) ||
185
186
next . match ( negative ) ) &&
@@ -266,7 +267,8 @@ function parse (args, opts) {
266
267
267
268
if ( ! broken && key !== '-' ) {
268
269
// 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 ) {
270
272
i = eatNargs ( i , key , args )
271
273
// array format = '-f a b c'
272
274
} else if ( checkAllAliases ( key , flags . arrays ) && args . length > i + 1 ) {
@@ -347,6 +349,11 @@ function parse (args, opts) {
347
349
var ii
348
350
const toEat = checkAllAliases ( key , flags . nargs )
349
351
352
+ if ( toEat === 0 ) {
353
+ setArg ( key , defaultValue ( key ) )
354
+ return i
355
+ }
356
+
350
357
// nargs will not consume flag arguments, e.g., -abc, --foo,
351
358
// and terminates when one is observed.
352
359
var available = 0
@@ -747,7 +754,7 @@ function parse (args, opts) {
747
754
var toCheck = [ ] . concat ( flags . aliases [ key ] || [ ] , key )
748
755
749
756
toCheck . forEach ( function ( key ) {
750
- if ( flag [ key ] ) isSet = flag [ key ]
757
+ if ( flag . hasOwnProperty ( key ) ) isSet = flag [ key ]
751
758
} )
752
759
753
760
return isSet
0 commit comments