@@ -156,15 +156,15 @@ function parse (args, opts) {
156
156
args . splice ( i + 1 , 0 , m [ 2 ] )
157
157
i = eatNargs ( i , m [ 1 ] , args )
158
158
// arrays format = '--f=a b c'
159
- } else if ( checkAllAliases ( m [ 1 ] , flags . arrays ) && args . length > i + 1 ) {
159
+ } else if ( checkAllAliases ( m [ 1 ] , flags . arrays ) ) {
160
160
args . splice ( i + 1 , 0 , m [ 2 ] )
161
161
i = eatArray ( i , m [ 1 ] , args )
162
162
} else {
163
163
setArg ( m [ 1 ] , m [ 2 ] )
164
164
}
165
165
} else if ( arg . match ( negatedBoolean ) && configuration [ 'boolean-negation' ] ) {
166
166
key = arg . match ( negatedBoolean ) [ 1 ]
167
- setArg ( key , false )
167
+ setArg ( key , checkAllAliases ( key , flags . arrays ) ? [ false ] : false )
168
168
169
169
// -- seperated by space.
170
170
} else if ( arg . match ( / ^ - - .+ / ) || (
@@ -177,7 +177,7 @@ function parse (args, opts) {
177
177
if ( checkAllAliases ( key , flags . nargs ) !== false ) {
178
178
i = eatNargs ( i , key , args )
179
179
// array format = '--foo a b c'
180
- } else if ( checkAllAliases ( key , flags . arrays ) && args . length > i + 1 ) {
180
+ } else if ( checkAllAliases ( key , flags . arrays ) ) {
181
181
i = eatArray ( i , key , args )
182
182
} else {
183
183
next = args [ i + 1 ]
@@ -230,7 +230,7 @@ function parse (args, opts) {
230
230
args . splice ( i + 1 , 0 , value )
231
231
i = eatNargs ( i , key , args )
232
232
// array format = '-f=a b c'
233
- } else if ( checkAllAliases ( key , flags . arrays ) && args . length > i + 1 ) {
233
+ } else if ( checkAllAliases ( key , flags . arrays ) ) {
234
234
args . splice ( i + 1 , 0 , value )
235
235
i = eatArray ( i , key , args )
236
236
} else {
@@ -271,7 +271,7 @@ function parse (args, opts) {
271
271
if ( checkAllAliases ( key , flags . nargs ) !== false ) {
272
272
i = eatNargs ( i , key , args )
273
273
// array format = '-f a b c'
274
- } else if ( checkAllAliases ( key , flags . arrays ) && args . length > i + 1 ) {
274
+ } else if ( checkAllAliases ( key , flags . arrays ) ) {
275
275
i = eatArray ( i , key , args )
276
276
} else {
277
277
next = args [ i + 1 ]
@@ -376,30 +376,27 @@ function parse (args, opts) {
376
376
// following it... YUM!
377
377
// e.g., --foo apple banana cat becomes ["apple", "banana", "cat"]
378
378
function eatArray ( i , key , args ) {
379
- var start = i + 1
380
- var argsToSet = [ ]
381
- var multipleArrayFlag = i > 0
382
- for ( var ii = i + 1 ; ii < args . length ; ii ++ ) {
383
- if ( / ^ - / . test ( args [ ii ] ) && ! negative . test ( args [ ii ] ) ) {
384
- if ( ii === start ) {
385
- setArg ( key , defaultForType ( 'array' ) )
386
- }
387
- multipleArrayFlag = true
388
- break
379
+ let argsToSet = [ ]
380
+ let next = args [ i + 1 ]
381
+
382
+ if ( checkAllAliases ( key , flags . bools ) && ! ( / ^ ( t r u e | f a l s e ) $ / . test ( next ) ) ) {
383
+ argsToSet . push ( true )
384
+ } else if ( isUndefined ( next ) || ( / ^ - / . test ( next ) && ! negative . test ( next ) ) ) {
385
+ // for keys without value ==> argsToSet remains an empty []
386
+ // set user default value, if available
387
+ if ( defaults . hasOwnProperty ( key ) ) {
388
+ argsToSet . push ( defaults [ key ] )
389
389
}
390
- i = ii
391
- argsToSet . push ( args [ ii ] )
392
- }
393
- if ( multipleArrayFlag ) {
394
- setArg ( key , argsToSet . map ( function ( arg ) {
395
- return processValue ( key , arg )
396
- } ) )
397
390
} else {
398
- argsToSet . forEach ( function ( arg ) {
399
- setArg ( key , arg )
400
- } )
391
+ for ( var ii = i + 1 ; ii < args . length ; ii ++ ) {
392
+ next = args [ ii ]
393
+ if ( / ^ - / . test ( next ) && ! negative . test ( next ) ) break
394
+ i = ii
395
+ argsToSet . push ( processValue ( key , next ) )
396
+ }
401
397
}
402
398
399
+ setArg ( key , argsToSet )
403
400
return i
404
401
}
405
402
@@ -791,6 +788,7 @@ function parse (args, opts) {
791
788
792
789
if ( checkAllAliases ( key , flags . strings ) ) type = 'string'
793
790
else if ( checkAllAliases ( key , flags . numbers ) ) type = 'number'
791
+ else if ( checkAllAliases ( key , flags . bools ) ) type = 'boolean'
794
792
else if ( checkAllAliases ( key , flags . arrays ) ) type = 'array'
795
793
796
794
return type
0 commit comments