@@ -11,7 +11,7 @@ import type {
1111} from 'citty' ;
1212import { generateFigSpec } from './fig' ;
1313import { CompletionConfig , assertDoubleDashes } from './shared' ;
14- import { OptionHandler , Command , Option , OptionsMap , noopHandler } from './t' ;
14+ import { OptionHandler , Command , Option , OptionsMap } from './t' ;
1515import t from './t' ;
1616
1717function quoteIfNeeded ( path : string ) {
@@ -144,21 +144,19 @@ async function handleSubCommands(
144144 : conf . alias
145145 : undefined ;
146146
147- // Detect boolean options and use appropriate handler
148- const isBoolean = conf . type === 'boolean' ;
149- const customHandler = subCompletionConfig ?. options ?. [ argName ] ;
150- const handler = isBoolean ? noopHandler : customHandler ;
151-
152- // Add option using t.ts API - auto-detection handles boolean vs value options
153- if ( shortFlag ) {
154- if ( handler ) {
147+ // Add option using t.ts API - store without -- prefix
148+ const handler = subCompletionConfig ?. options ?. [ argName ] ;
149+ if ( handler ) {
150+ // Has custom handler → value option
151+ if ( shortFlag ) {
155152 command . option ( argName , conf . description ?? '' , handler , shortFlag ) ;
156153 } else {
157- command . option ( argName , conf . description ?? '' , shortFlag ) ;
154+ command . option ( argName , conf . description ?? '' , handler ) ;
158155 }
159156 } else {
160- if ( handler ) {
161- command . option ( argName , conf . description ?? '' , handler ) ;
157+ // No custom handler → boolean flag
158+ if ( shortFlag ) {
159+ command . option ( argName , conf . description ?? '' , shortFlag ) ;
162160 } else {
163161 command . option ( argName , conf . description ?? '' ) ;
164162 }
@@ -215,16 +213,30 @@ export default async function tab<TArgs extends ArgsDef>(
215213 for ( const [ argName , argConfig ] of Object . entries ( instance . args ) ) {
216214 const conf = argConfig as ArgDef ;
217215
218- // Detect boolean options and use appropriate handler
219- const isBoolean = conf . type === 'boolean' ;
220- const customHandler = completionConfig ?. options ?. [ argName ] ;
221- const handler = isBoolean ? noopHandler : customHandler ;
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 ;
222223
223- // Add option using t.ts API - auto-detection handles boolean vs value options
224+ // Add option using t.ts API - store without -- prefix
225+ const handler = completionConfig ?. options ?. [ argName ] ;
224226 if ( handler ) {
225- t . option ( argName , conf . description ?? '' , 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+ }
226233 } else {
227- t . option ( argName , conf . description ?? '' ) ;
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+ }
228240 }
229241 }
230242 }
0 commit comments