@@ -143,7 +143,141 @@ describe("sub command", () => {
143143 } ) ;
144144} ) ;
145145
146+ describe ( "sub command with parent args" , ( ) => {
147+ it ( "resolves subcommand when parent has string arg" , async ( ) => {
148+ const runMock = vi . fn ( ) ;
149+
150+ const command = defineCommand ( {
151+ args : {
152+ name : { type : "string" } ,
153+ } ,
154+ subCommands : {
155+ build : {
156+ run : async ( ) => {
157+ runMock ( ) ;
158+ } ,
159+ } ,
160+ } ,
161+ } ) ;
162+
163+ await runMain ( command , { rawArgs : [ "--name" , "Citty" , "build" ] } ) ;
164+
165+ expect ( runMock ) . toHaveBeenCalledOnce ( ) ;
166+ } ) ;
167+
168+ it ( "resolves subcommand when parent has string arg with = syntax" , async ( ) => {
169+ const runMock = vi . fn ( ) ;
170+
171+ const command = defineCommand ( {
172+ args : {
173+ name : { type : "string" } ,
174+ } ,
175+ subCommands : {
176+ build : {
177+ run : async ( ) => {
178+ runMock ( ) ;
179+ } ,
180+ } ,
181+ } ,
182+ } ) ;
183+
184+ await runMain ( command , { rawArgs : [ "--name=Citty" , "build" ] } ) ;
185+
186+ expect ( runMock ) . toHaveBeenCalledOnce ( ) ;
187+ } ) ;
188+
189+ it ( "resolves subcommand when parent has string arg with alias" , async ( ) => {
190+ const runMock = vi . fn ( ) ;
191+
192+ const command = defineCommand ( {
193+ args : {
194+ name : { type : "string" , alias : "n" } ,
195+ } ,
196+ subCommands : {
197+ build : {
198+ run : async ( ) => {
199+ runMock ( ) ;
200+ } ,
201+ } ,
202+ } ,
203+ } ) ;
204+
205+ await runMain ( command , { rawArgs : [ "-n" , "Citty" , "build" ] } ) ;
206+
207+ expect ( runMock ) . toHaveBeenCalledOnce ( ) ;
208+ } ) ;
209+
210+ it ( "resolves subcommand when parent has enum arg" , async ( ) => {
211+ const runMock = vi . fn ( ) ;
212+
213+ const command = defineCommand ( {
214+ args : {
215+ env : { type : "enum" , options : [ "dev" , "prod" ] } ,
216+ } ,
217+ subCommands : {
218+ build : {
219+ run : async ( ) => {
220+ runMock ( ) ;
221+ } ,
222+ } ,
223+ } ,
224+ } ) ;
225+
226+ await runMain ( command , { rawArgs : [ "--env" , "prod" , "build" ] } ) ;
227+
228+ expect ( runMock ) . toHaveBeenCalledOnce ( ) ;
229+ } ) ;
230+
231+ it ( "boolean arg does not consume next token as value" , async ( ) => {
232+ const runMock = vi . fn ( ) ;
233+
234+ const command = defineCommand ( {
235+ args : {
236+ verbose : { type : "boolean" } ,
237+ } ,
238+ subCommands : {
239+ build : {
240+ run : async ( ) => {
241+ runMock ( ) ;
242+ } ,
243+ } ,
244+ } ,
245+ } ) ;
246+
247+ await runMain ( command , { rawArgs : [ "--verbose" , "build" ] } ) ;
248+
249+ expect ( runMock ) . toHaveBeenCalledOnce ( ) ;
250+ } ) ;
251+ } ) ;
252+
146253describe ( "resolveSubCommand" , ( ) => {
254+ it ( "resolves subcommand with parent string args" , async ( ) => {
255+ const command = defineCommand ( {
256+ args : {
257+ name : { type : "string" } ,
258+ } ,
259+ subCommands : {
260+ build : {
261+ args : {
262+ target : { type : "positional" } ,
263+ } ,
264+ } ,
265+ } ,
266+ } ) ;
267+
268+ const [ subCommand ] = await commandModule . resolveSubCommand ( command , [
269+ "--name" ,
270+ "Citty" ,
271+ "build" ,
272+ "prod" ,
273+ ] ) ;
274+
275+ expect ( subCommand ) . toBeDefined ( ) ;
276+ expect ( subCommand . args ) . toEqual ( {
277+ target : { type : "positional" } ,
278+ } ) ;
279+ } ) ;
280+
147281 it ( "resolves the sub command" , async ( ) => {
148282 const command = defineCommand ( {
149283 subCommands : {
0 commit comments