@@ -85,8 +85,6 @@ function convertOptionHandler(handler: any): OptionHandler {
8585 } ;
8686}
8787
88- const noopOptionHandler : OptionHandler = function ( ) { } ;
89-
9088async function handleSubCommands (
9189 subCommands : SubCommandsDef ,
9290 parentCmd ?: string ,
@@ -105,7 +103,7 @@ async function handleSubCommands(
105103
106104 // Add command using t.ts API
107105 const commandName = parentCmd ? `${ parentCmd } ${ cmd } ` : cmd ;
108- const command = t . command ( cmd , meta . description ) ;
106+ const command = t . command ( commandName , meta . description ) ;
109107
110108 // Set args for the command if it has positional arguments
111109 if ( isPositional && config . args ) {
@@ -138,9 +136,6 @@ async function handleSubCommands(
138136 if ( config . args ) {
139137 for ( const [ argName , argConfig ] of Object . entries ( config . args ) ) {
140138 const conf = argConfig as ArgDef ;
141- if ( conf . type === 'positional' ) {
142- continue ;
143- }
144139 // Extract alias from the config if it exists
145140 const shortFlag =
146141 typeof conf === 'object' && 'alias' in conf
@@ -150,12 +145,22 @@ async function handleSubCommands(
150145 : undefined ;
151146
152147 // Add option using t.ts API - store without -- prefix
153- command . option (
154- argName ,
155- conf . description ?? '' ,
156- subCompletionConfig ?. options ?. [ argName ] ?? noopOptionHandler ,
157- shortFlag
158- ) ;
148+ const handler = subCompletionConfig ?. options ?. [ argName ] ;
149+ if ( handler ) {
150+ // Has custom handler → value option
151+ if ( shortFlag ) {
152+ command . option ( argName , conf . description ?? '' , handler , shortFlag ) ;
153+ } else {
154+ command . option ( argName , conf . description ?? '' , handler ) ;
155+ }
156+ } else {
157+ // No custom handler → boolean flag
158+ if ( shortFlag ) {
159+ command . option ( argName , conf . description ?? '' , shortFlag ) ;
160+ } else {
161+ command . option ( argName , conf . description ?? '' ) ;
162+ }
163+ }
159164 }
160165 }
161166 }
@@ -206,13 +211,33 @@ export default async function tab<TArgs extends ArgsDef>(
206211
207212 if ( instance . args ) {
208213 for ( const [ argName , argConfig ] of Object . entries ( instance . args ) ) {
209- const conf = argConfig as PositionalArgDef ;
214+ const conf = argConfig as ArgDef ;
215+
216+ // Extract alias (same logic as subcommands)
217+ const shortFlag =
218+ typeof conf === 'object' && 'alias' in conf
219+ ? Array . isArray ( conf . alias )
220+ ? conf . alias [ 0 ]
221+ : conf . alias
222+ : undefined ;
223+
210224 // Add option using t.ts API - store without -- prefix
211- t . option (
212- argName ,
213- conf . description ?? '' ,
214- completionConfig ?. options ?. [ argName ] ?? noopOptionHandler
215- ) ;
225+ const handler = completionConfig ?. options ?. [ argName ] ;
226+ if ( handler ) {
227+ // Has custom handler → value option
228+ if ( shortFlag ) {
229+ t . option ( argName , conf . description ?? '' , handler , shortFlag ) ;
230+ } else {
231+ t . option ( argName , conf . description ?? '' , handler ) ;
232+ }
233+ } else {
234+ // No custom handler → boolean flag
235+ if ( shortFlag ) {
236+ t . option ( argName , conf . description ?? '' , shortFlag ) ;
237+ } else {
238+ t . option ( argName , conf . description ?? '' ) ;
239+ }
240+ }
216241 }
217242 }
218243
0 commit comments