@@ -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 ( / ^ - - .+ / ) || (
@@ -176,7 +176,7 @@ function parse (args, opts) {
176
176
if ( checkAllAliases ( key , flags . nargs ) ) {
177
177
i = eatNargs ( i , key , args )
178
178
// array format = '--foo a b c'
179
- } else if ( checkAllAliases ( key , flags . arrays ) && args . length > i + 1 ) {
179
+ } else if ( checkAllAliases ( key , flags . arrays ) ) {
180
180
i = eatArray ( i , key , args )
181
181
} else {
182
182
next = flags . nargs [ key ] === 0 ? undefined : args [ i + 1 ]
@@ -369,30 +369,24 @@ function parse (args, opts) {
369
369
// following it... YUM!
370
370
// e.g., --foo apple banana cat becomes ["apple", "banana", "cat"]
371
371
function eatArray ( i , key , args ) {
372
- var start = i + 1
373
- var argsToSet = [ ]
374
- var multipleArrayFlag = i > 0
375
- for ( var ii = i + 1 ; ii < args . length ; ii ++ ) {
376
- if ( / ^ - / . test ( args [ ii ] ) && ! negative . test ( args [ ii ] ) ) {
377
- if ( ii === start ) {
378
- setArg ( key , defaultForType ( 'array' ) )
379
- }
380
- multipleArrayFlag = true
381
- break
382
- }
383
- i = ii
384
- argsToSet . push ( args [ ii ] )
385
- }
386
- if ( multipleArrayFlag ) {
387
- setArg ( key , argsToSet . map ( function ( arg ) {
388
- return processValue ( key , arg )
389
- } ) )
372
+ let argsToSet = [ ]
373
+ let next = args [ i + 1 ]
374
+
375
+ if ( checkAllAliases ( key , flags . bools ) && ! ( / ^ ( t r u e | f a l s e ) $ / . test ( next ) ) ) {
376
+ argsToSet . push ( true )
377
+ } else if ( / ^ - / . test ( next ) && ! negative . test ( next ) ) {
378
+ // if ( TODO: set user default value, if available )
379
+ // else ( key without value ==> argsToSet === [] )
390
380
} else {
391
- argsToSet . forEach ( function ( arg ) {
392
- setArg ( key , arg )
393
- } )
381
+ for ( var ii = i + 1 ; ii < args . length ; ii ++ ) {
382
+ next = args [ ii ]
383
+ if ( / ^ - / . test ( next ) && ! negative . test ( next ) ) break
384
+ i = ii
385
+ argsToSet . push ( processValue ( key , next ) )
386
+ }
394
387
}
395
388
389
+ setArg ( key , argsToSet )
396
390
return i
397
391
}
398
392
0 commit comments