@@ -273,8 +273,9 @@ function parse (args, opts) {
273273 applyEnvVars ( argv , false )
274274 applyDefaultsAndAliases ( argv , flags . aliases , defaults )
275275
276+ // for any counts either not in args or without an explicit default, set to 0
276277 Object . keys ( flags . counts ) . forEach ( function ( key ) {
277- setArg ( key , defaults [ key ] )
278+ if ( ! hasKey ( argv , key . split ( '.' ) ) ) setArg ( key , 0 )
278279 } )
279280
280281 notFlags . forEach ( function ( key ) {
@@ -334,7 +335,8 @@ function parse (args, opts) {
334335 if ( ! isUndefined ( val ) && ! isNumber ( val ) && checkAllAliases ( key , flags . numbers ) ) value = NaN
335336 }
336337
337- if ( checkAllAliases ( key , flags . counts ) ) {
338+ // increment a count given as arg (either no value or value parsed as boolean)
339+ if ( checkAllAliases ( key , flags . counts ) && ( isUndefined ( value ) || typeof value === 'boolean' ) ) {
338340 value = increment
339341 }
340342
@@ -514,7 +516,7 @@ function parse (args, opts) {
514516 o [ key ] = increment ( o [ key ] )
515517 } else if ( o [ key ] === undefined && checkAllAliases ( key , flags . arrays ) ) {
516518 o [ key ] = Array . isArray ( value ) ? value : [ value ]
517- } else if ( o [ key ] === undefined || checkAllAliases ( key , flags . bools ) ) {
519+ } else if ( o [ key ] === undefined || checkAllAliases ( key , flags . bools ) || checkAllAliases ( key , flags . counts ) ) {
518520 o [ key ] = value
519521 } else if ( Array . isArray ( o [ key ] ) ) {
520522 o [ key ] . push ( value )
@@ -665,8 +667,11 @@ function combineAliases (aliases) {
665667 return combined
666668}
667669
670+ // this function should only be called when a count is given as an arg
671+ // it is NOT called to set a default value
672+ // thus we can start the count at 1 instead of 0
668673function increment ( orig ) {
669- return orig !== undefined ? orig + 1 : 0
674+ return orig !== undefined ? orig + 1 : 1
670675}
671676
672677function Parser ( args , opts ) {
0 commit comments