@@ -167,15 +167,15 @@ function parse (args, opts) {
167
167
args . splice ( i + 1 , 0 , m [ 2 ] )
168
168
i = eatNargs ( i , m [ 1 ] , args )
169
169
// arrays format = '--f=a b c'
170
- } else if ( checkAllAliases ( m [ 1 ] , flags . arrays ) && args . length > i + 1 ) {
170
+ } else if ( checkAllAliases ( m [ 1 ] , flags . arrays ) ) {
171
171
args . splice ( i + 1 , 0 , m [ 2 ] )
172
172
i = eatArray ( i , m [ 1 ] , args )
173
173
} else {
174
174
setArg ( m [ 1 ] , m [ 2 ] )
175
175
}
176
176
} else if ( arg . match ( negatedBoolean ) && configuration [ 'boolean-negation' ] ) {
177
177
key = arg . match ( negatedBoolean ) [ 1 ]
178
- setArg ( key , false )
178
+ setArg ( key , checkAllAliases ( key , flags . arrays ) ? [ false ] : false )
179
179
180
180
// -- seperated by space.
181
181
} else if ( arg . match ( / ^ - - .+ / ) || (
@@ -188,7 +188,7 @@ function parse (args, opts) {
188
188
if ( checkAllAliases ( key , flags . nargs ) !== false ) {
189
189
i = eatNargs ( i , key , args )
190
190
// array format = '--foo a b c'
191
- } else if ( checkAllAliases ( key , flags . arrays ) && args . length > i + 1 ) {
191
+ } else if ( checkAllAliases ( key , flags . arrays ) ) {
192
192
i = eatArray ( i , key , args )
193
193
} else {
194
194
next = args [ i + 1 ]
@@ -241,7 +241,7 @@ function parse (args, opts) {
241
241
args . splice ( i + 1 , 0 , value )
242
242
i = eatNargs ( i , key , args )
243
243
// array format = '-f=a b c'
244
- } else if ( checkAllAliases ( key , flags . arrays ) && args . length > i + 1 ) {
244
+ } else if ( checkAllAliases ( key , flags . arrays ) ) {
245
245
args . splice ( i + 1 , 0 , value )
246
246
i = eatArray ( i , key , args )
247
247
} else {
@@ -282,7 +282,7 @@ function parse (args, opts) {
282
282
if ( checkAllAliases ( key , flags . nargs ) !== false ) {
283
283
i = eatNargs ( i , key , args )
284
284
// array format = '-f a b c'
285
- } else if ( checkAllAliases ( key , flags . arrays ) && args . length > i + 1 ) {
285
+ } else if ( checkAllAliases ( key , flags . arrays ) ) {
286
286
i = eatArray ( i , key , args )
287
287
} else {
288
288
next = args [ i + 1 ]
@@ -387,30 +387,27 @@ function parse (args, opts) {
387
387
// following it... YUM!
388
388
// e.g., --foo apple banana cat becomes ["apple", "banana", "cat"]
389
389
function eatArray ( i , key , args ) {
390
- var start = i + 1
391
- var argsToSet = [ ]
392
- var multipleArrayFlag = i > 0
393
- for ( var ii = i + 1 ; ii < args . length ; ii ++ ) {
394
- if ( / ^ - / . test ( args [ ii ] ) && ! negative . test ( args [ ii ] ) ) {
395
- if ( ii === start ) {
396
- setArg ( key , defaultForType ( 'array' ) )
397
- }
398
- multipleArrayFlag = true
399
- break
390
+ let argsToSet = [ ]
391
+ let next = args [ i + 1 ]
392
+
393
+ if ( checkAllAliases ( key , flags . bools ) && ! ( / ^ ( t r u e | f a l s e ) $ / . test ( next ) ) ) {
394
+ argsToSet . push ( true )
395
+ } else if ( isUndefined ( next ) || ( / ^ - / . test ( next ) && ! negative . test ( next ) ) ) {
396
+ // for keys without value ==> argsToSet remains an empty []
397
+ // set user default value, if available
398
+ if ( defaults . hasOwnProperty ( key ) ) {
399
+ argsToSet . push ( defaults [ key ] )
400
400
}
401
- i = ii
402
- argsToSet . push ( args [ ii ] )
403
- }
404
- if ( multipleArrayFlag ) {
405
- setArg ( key , argsToSet . map ( function ( arg ) {
406
- return processValue ( key , arg )
407
- } ) )
408
401
} else {
409
- argsToSet . forEach ( function ( arg ) {
410
- setArg ( key , arg )
411
- } )
402
+ for ( var ii = i + 1 ; ii < args . length ; ii ++ ) {
403
+ next = args [ ii ]
404
+ if ( / ^ - / . test ( next ) && ! negative . test ( next ) ) break
405
+ i = ii
406
+ argsToSet . push ( processValue ( key , next ) )
407
+ }
412
408
}
413
409
410
+ setArg ( key , argsToSet )
414
411
return i
415
412
}
416
413
@@ -802,6 +799,7 @@ function parse (args, opts) {
802
799
803
800
if ( checkAllAliases ( key , flags . strings ) ) type = 'string'
804
801
else if ( checkAllAliases ( key , flags . numbers ) ) type = 'number'
802
+ else if ( checkAllAliases ( key , flags . bools ) ) type = 'boolean'
805
803
else if ( checkAllAliases ( key , flags . arrays ) ) type = 'array'
806
804
807
805
return type
0 commit comments