@@ -156,15 +156,15 @@ function parse (args, opts) {
156156 args . splice ( i + 1 , 0 , m [ 2 ] )
157157 i = eatNargs ( i , m [ 1 ] , args )
158158 // 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 ) ) {
160160 args . splice ( i + 1 , 0 , m [ 2 ] )
161161 i = eatArray ( i , m [ 1 ] , args )
162162 } else {
163163 setArg ( m [ 1 ] , m [ 2 ] )
164164 }
165165 } else if ( arg . match ( negatedBoolean ) && configuration [ 'boolean-negation' ] ) {
166166 key = arg . match ( negatedBoolean ) [ 1 ]
167- setArg ( key , false )
167+ setArg ( key , checkAllAliases ( key , flags . arrays ) ? [ false ] : false )
168168
169169 // -- seperated by space.
170170 } else if ( arg . match ( / ^ - - .+ / ) || (
@@ -176,7 +176,7 @@ function parse (args, opts) {
176176 if ( checkAllAliases ( key , flags . nargs ) ) {
177177 i = eatNargs ( i , key , args )
178178 // array format = '--foo a b c'
179- } else if ( checkAllAliases ( key , flags . arrays ) && args . length > i + 1 ) {
179+ } else if ( checkAllAliases ( key , flags . arrays ) ) {
180180 i = eatArray ( i , key , args )
181181 } else {
182182 next = flags . nargs [ key ] === 0 ? undefined : args [ i + 1 ]
@@ -369,30 +369,24 @@ function parse (args, opts) {
369369 // following it... YUM!
370370 // e.g., --foo apple banana cat becomes ["apple", "banana", "cat"]
371371 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 === [] )
390380 } 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+ }
394387 }
395388
389+ setArg ( key , argsToSet )
396390 return i
397391 }
398392
0 commit comments