@@ -62,7 +62,10 @@ let commands = {
62
62
args : {
63
63
'--input' : { type : String , description : 'Input file' } ,
64
64
'--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
+ } ,
66
69
'--poll' : {
67
70
type : Boolean ,
68
71
description : 'Use polling instead of filesystem events when watching' ,
@@ -159,8 +162,8 @@ let args = (() => {
159
162
let flag = result [ '_' ] [ i ]
160
163
if ( ! flag . startsWith ( '-' ) ) continue
161
164
162
- let flagName = flag
163
- let handler = flags [ flag ]
165
+ let [ flagName , flagValue ] = flag . split ( '=' )
166
+ let handler = flags [ flagName ]
164
167
165
168
// Resolve flagName & handler
166
169
while ( typeof handler === 'string' ) {
@@ -173,19 +176,27 @@ let args = (() => {
173
176
let args = [ ]
174
177
let offset = i + 1
175
178
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 )
180
188
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
+ }
183
197
184
198
// 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 )
189
200
}
190
201
191
202
// Ensure that the `command` is always the first argument in the `args`.
0 commit comments