44 *
55 * A git-like CLI that demonstrates:
66 *
7- * - Nested command groups (e.g., `git remote add`)
7+ * - Nested command groups with aliases (e.g., `git r add` for `git remote add`)
88 * - Factory pattern for full type inference of parent globals
99 * - Unlimited nesting depth
1010 * - Parent globals flowing to nested handlers
1111 * - Default subcommands
12+ * - Command aliases at both parent and nested levels
1213 *
13- * Usage: npx tsx examples/nested-commands.ts remote add origin
14- * https://github.com/... npx tsx examples/nested-commands.ts remote remove
15- * origin npx tsx examples/nested-commands.ts config get user.name npx tsx
16- * examples/nested-commands.ts --verbose remote add origin https://... npx tsx
17- * examples/nested-commands.ts --help npx tsx examples/nested-commands.ts remote
18- * --help
14+ * @example
15+ *
16+ * ```sh
17+ * npx tsx examples/nested-commands.ts remote add origin https://github.com/...
18+ * npx tsx examples/nested-commands.ts r add origin https://... # 'r' alias
19+ * npx tsx examples/nested-commands.ts remote rm origin # 'rm' alias
20+ * npx tsx examples/nested-commands.ts config get user.name
21+ * npx tsx examples/nested-commands.ts cfg get user.name # 'cfg' alias
22+ * npx tsx examples/nested-commands.ts --verbose remote add origin https://...
23+ * npx tsx examples/nested-commands.ts --help
24+ * npx tsx examples/nested-commands.ts remote --help
25+ * ```
1926 */
2027import { bargs , opt , pos } from '../src/index.js' ;
2128
@@ -53,6 +60,7 @@ await bargs('git-like', {
5360 // ─────────────────────────────────────────────────────────────────────────────
5461 // FACTORY PATTERN: Full type inference for parent globals!
5562 // The factory receives a builder that already has parent globals typed.
63+ // Nested command groups can have aliases too (e.g., 'r' for 'remote')
5664 // ─────────────────────────────────────────────────────────────────────────────
5765 . command (
5866 'remote' ,
@@ -95,7 +103,8 @@ await bargs('git-like', {
95103 console . log ( `Removed remote '${ name } '` ) ;
96104 }
97105 } ,
98- 'Remove a remote' ,
106+ // Subcommands can have aliases too
107+ { aliases : [ 'rm' , 'del' ] , description : 'Remove a remote' } ,
99108 )
100109 . command (
101110 'list' ,
@@ -114,10 +123,11 @@ await bargs('git-like', {
114123 }
115124 }
116125 } ,
117- ' List remotes',
126+ { aliases : [ 'ls' ] , description : ' List remotes' } ,
118127 )
119128 . defaultCommand ( 'list' ) ,
120- 'Manage remotes' ,
129+ // Parent command group has aliases
130+ { aliases : [ 'r' ] , description : 'Manage remotes' } ,
121131 )
122132
123133 // ─────────────────────────────────────────────────────────────────────────────
@@ -139,7 +149,7 @@ await bargs('git-like', {
139149 }
140150 console . log ( value ) ;
141151 } ,
142- ' Get a config value',
152+ { aliases : [ 'g' ] , description : ' Get a config value' } ,
143153 )
144154 . command (
145155 'set' ,
@@ -155,9 +165,9 @@ await bargs('git-like', {
155165 console . log ( `Set ${ key } = ${ value } ` ) ;
156166 }
157167 } ,
158- ' Set a config value',
168+ { aliases : [ 's' ] , description : ' Set a config value' } ,
159169 ) ,
160- ' Manage configuration',
170+ { aliases : [ 'cfg' , 'c' ] , description : ' Manage configuration' } ,
161171 )
162172
163173 // ─────────────────────────────────────────────────────────────────────────────
@@ -174,7 +184,7 @@ await bargs('git-like', {
174184 console . log ( `Config entries: ${ config . size } ` ) ;
175185 }
176186 } ,
177- ' Show status',
187+ { aliases : [ 'st' , 's' ] , description : ' Show status' } ,
178188 )
179189 . defaultCommand ( 'status' )
180190 . parseAsync ( ) ;
0 commit comments