File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -204,16 +204,18 @@ export class Massarg<Options> {
204204 const value = option . parse ! ( tempValue , this . data )
205205 this . _addOptionToData ( option , value )
206206
207- continue
207+ // continue
208208 }
209209
210210 const command = this . _commands . find ( ( o ) => o . name = = = arg || o . aliases ?. includes ( arg ) )
211211
212212 if ( command ) {
213213 if ( this . _runCommand ) {
214- continue
214+ this . data . extras . push ( arg )
215+ // continue
216+ } else {
217+ this . _runCommand = command
215218 }
216- this . _runCommand = command
217219 }
218220
219221 if ( ! option && ! command ) {
Original file line number Diff line number Diff line change @@ -23,4 +23,28 @@ describe("Commands", () => {
2323 . parse ( [ "c" ] )
2424 expect ( cmd ) . toHaveBeenCalledTimes ( 1 )
2525 } )
26+
27+ test ( "should consume the first command, then treat the rest as extras" , ( ) => {
28+ const cmd = jest . fn ( )
29+ const opt = jest . fn ( )
30+ const def = massarg ( )
31+ . command ( {
32+ name : "cmd" ,
33+ aliases : [ "c" ] ,
34+ run : cmd ,
35+ } )
36+ . command ( {
37+ name : "opt" ,
38+ aliases : [ "o" ] ,
39+ run : opt ,
40+ } )
41+
42+ const options = def . parseArgs ( [ "cmd" , "opt" ] )
43+
44+ def . parse ( [ "cmd" , "opt" ] )
45+
46+ expect ( cmd ) . toHaveBeenCalledTimes ( 1 )
47+ expect ( opt ) . not . toHaveBeenCalled ( )
48+ expect ( options . extras ) . toContain ( "opt" )
49+ } )
2650} )
You can’t perform that action at this time.
0 commit comments