@@ -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 ( / ^ - - .+ / ) || (
@@ -177,7 +177,7 @@ function parse (args, opts) {
177177 if ( checkAllAliases ( key , flags . nargs ) !== false ) {
178178 i = eatNargs ( i , key , args )
179179 // array format = '--foo a b c'
180- } else if ( checkAllAliases ( key , flags . arrays ) && args . length > i + 1 ) {
180+ } else if ( checkAllAliases ( key , flags . arrays ) ) {
181181 i = eatArray ( i , key , args )
182182 } else {
183183 next = args [ i + 1 ]
@@ -230,7 +230,7 @@ function parse (args, opts) {
230230 args . splice ( i + 1 , 0 , value )
231231 i = eatNargs ( i , key , args )
232232 // array format = '-f=a b c'
233- } else if ( checkAllAliases ( key , flags . arrays ) && args . length > i + 1 ) {
233+ } else if ( checkAllAliases ( key , flags . arrays ) ) {
234234 args . splice ( i + 1 , 0 , value )
235235 i = eatArray ( i , key , args )
236236 } else {
@@ -271,7 +271,7 @@ function parse (args, opts) {
271271 if ( checkAllAliases ( key , flags . nargs ) !== false ) {
272272 i = eatNargs ( i , key , args )
273273 // array format = '-f a b c'
274- } else if ( checkAllAliases ( key , flags . arrays ) && args . length > i + 1 ) {
274+ } else if ( checkAllAliases ( key , flags . arrays ) ) {
275275 i = eatArray ( i , key , args )
276276 } else {
277277 next = args [ i + 1 ]
@@ -376,30 +376,27 @@ function parse (args, opts) {
376376 // following it... YUM!
377377 // e.g., --foo apple banana cat becomes ["apple", "banana", "cat"]
378378 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 ] )
389389 }
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- } ) )
397390 } 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+ }
401397 }
402398
399+ setArg ( key , argsToSet )
403400 return i
404401 }
405402
@@ -791,6 +788,7 @@ function parse (args, opts) {
791788
792789 if ( checkAllAliases ( key , flags . strings ) ) type = 'string'
793790 else if ( checkAllAliases ( key , flags . numbers ) ) type = 'number'
791+ else if ( checkAllAliases ( key , flags . bools ) ) type = 'boolean'
794792 else if ( checkAllAliases ( key , flags . arrays ) ) type = 'array'
795793
796794 return type
0 commit comments