@@ -27,11 +27,11 @@ class MyApp {
2727 static port: number = 8080 ;
2828
2929 @argument ({ description: " Input file" })
30- @required ( )
30+ @type ( " string " )
3131 static input: string ;
3232
33- @argument ({ description: " Output file" , optional: true })
34- static output: string ;
33+ @argument ({ description: " Output file" })
34+ static output: string = " output.txt " ;
3535}
3636
3737// Access parsed values
@@ -316,6 +316,62 @@ class Config {
316316}
317317```
318318
319+ ### Consuming Parsed Commands
320+
321+ ``` typescript
322+ @command
323+ class ServeCommand {
324+ @description (" Port to serve on" )
325+ static port: number = 3000 ;
326+
327+ @description (" Enable watch mode" )
328+ static watch: boolean = false ;
329+ }
330+
331+ @command
332+ class BuildCommand {
333+ @description (" Enable production mode" )
334+ static production: boolean = false ;
335+
336+ @argument ({ description: " Output directory" })
337+ static output: string = " dist" ;
338+ }
339+
340+ @parse (Deno .args , { name: " myapp" })
341+ class MyApp {
342+ @description (" Enable verbose logging" )
343+ static verbose: boolean = false ;
344+
345+ @subCommand (ServeCommand )
346+ static serve: ServeCommand ;
347+
348+ @subCommand (BuildCommand )
349+ static build: BuildCommand ;
350+ }
351+
352+ // Check which command was used and execute accordingly
353+ if (MyApp .serve ) {
354+ console .log (` Starting server on port ${ServeCommand .port } ` );
355+ if (ServeCommand .watch ) {
356+ console .log (" Watch mode enabled" );
357+ }
358+ // Start your server logic here
359+ } else if (MyApp .build ) {
360+ console .log (` Building to ${BuildCommand .output } ` );
361+ if (BuildCommand .production ) {
362+ console .log (" Production build enabled" );
363+ }
364+ // Run your build logic here
365+ } else {
366+ console .log (" No command specified. Use --help for usage." );
367+ }
368+
369+ // Global options are always available
370+ if (MyApp .verbose ) {
371+ console .log (" Verbose logging enabled" );
372+ }
373+ ```
374+
319375## License
320376
321377MIT
0 commit comments