@@ -62,7 +62,10 @@ let commands = {
6262 args : {
6363 '--input' : { type : String , description : 'Input file' } ,
6464 '--output' : { type : String , description : 'Output file' } ,
65- '--watch' : { type : Boolean , description : 'Watch for changes and rebuild as needed' } ,
65+ '--watch' : {
66+ type : oneOf ( String , Boolean ) ,
67+ description : 'Watch for changes and rebuild as needed' ,
68+ } ,
6669 '--poll' : {
6770 type : Boolean ,
6871 description : 'Use polling instead of filesystem events when watching' ,
@@ -159,8 +162,8 @@ let args = (() => {
159162 let flag = result [ '_' ] [ i ]
160163 if ( ! flag . startsWith ( '-' ) ) continue
161164
162- let flagName = flag
163- let handler = flags [ flag ]
165+ let [ flagName , flagValue ] = flag . split ( '=' )
166+ let handler = flags [ flagName ]
164167
165168 // Resolve flagName & handler
166169 while ( typeof handler === 'string' ) {
@@ -173,19 +176,27 @@ let args = (() => {
173176 let args = [ ]
174177 let offset = i + 1
175178
176- // Parse args for current flag
177- while ( result [ '_' ] [ offset ] && ! result [ '_' ] [ offset ] . startsWith ( '-' ) ) {
178- args . push ( result [ '_' ] [ offset ++ ] )
179- }
179+ // --flag value syntax was used so we need to pull `value` from `args`
180+ if ( flagValue === undefined ) {
181+ // Parse args for current flag
182+ while ( result [ '_' ] [ offset ] && ! result [ '_' ] [ offset ] . startsWith ( '-' ) ) {
183+ args . push ( result [ '_' ] [ offset ++ ] )
184+ }
185+
186+ // Cleanup manually parsed flags + args
187+ result [ '_' ] . splice ( i , 1 + args . length )
180188
181- // Cleanup manually parsed flags + args
182- result [ '_' ] . splice ( i , 1 + args . length )
189+ // No args were provided, use default value defined in handler
190+ // One arg was provided, use that directly
191+ // Multiple args were provided so pass them all in an array
192+ flagValue = args . length === 0 ? undefined : args . length === 1 ? args [ 0 ] : args
193+ } else {
194+ // Remove the whole flag from the args array
195+ result [ '_' ] . splice ( i , 1 )
196+ }
183197
184198 // Set the resolved value in the `result` object
185- result [ flagName ] = handler . type (
186- args . length === 0 ? undefined : args . length === 1 ? args [ 0 ] : args ,
187- flagName
188- )
199+ result [ flagName ] = handler . type ( flagValue , flagName )
189200 }
190201
191202 // Ensure that the `command` is always the first argument in the `args`.
0 commit comments