@@ -11,7 +11,7 @@ import type {
1111} from 'citty' ;
1212import { generateFigSpec } from './fig' ;
1313import { CompletionConfig , assertDoubleDashes } from './shared' ;
14- import { OptionHandler , Command , Option , OptionsMap } from './t' ;
14+ import { OptionHandler , Command , Option , OptionsMap , noopHandler } from './t' ;
1515import t from './t' ;
1616
1717function quoteIfNeeded ( path : string ) {
@@ -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 ,
@@ -146,15 +144,25 @@ async function handleSubCommands(
146144 : conf . alias
147145 : undefined ;
148146
149- // Add option using t.ts API - store without -- prefix
147+ // Detect boolean options and use appropriate handler
150148 const isBoolean = conf . type === 'boolean' ;
151- command . option (
152- argName ,
153- conf . description ?? '' ,
154- subCompletionConfig ?. options ?. [ argName ] ?? noopOptionHandler ,
155- shortFlag ,
156- isBoolean
157- ) ;
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 ) {
155+ command . option ( argName , conf . description ?? '' , handler , shortFlag ) ;
156+ } else {
157+ command . option ( argName , conf . description ?? '' , shortFlag ) ;
158+ }
159+ } else {
160+ if ( handler ) {
161+ command . option ( argName , conf . description ?? '' , handler ) ;
162+ } else {
163+ command . option ( argName , conf . description ?? '' ) ;
164+ }
165+ }
158166 }
159167 }
160168 }
@@ -206,15 +214,18 @@ export default async function tab<TArgs extends ArgsDef>(
206214 if ( instance . args ) {
207215 for ( const [ argName , argConfig ] of Object . entries ( instance . args ) ) {
208216 const conf = argConfig as ArgDef ;
209- // Add option using t.ts API - store without -- prefix
217+
218+ // Detect boolean options and use appropriate handler
210219 const isBoolean = conf . type === 'boolean' ;
211- t . option (
212- argName ,
213- conf . description ?? '' ,
214- completionConfig ?. options ?. [ argName ] ?? noopOptionHandler ,
215- undefined ,
216- isBoolean
217- ) ;
220+ const customHandler = completionConfig ?. options ?. [ argName ] ;
221+ const handler = isBoolean ? noopHandler : customHandler ;
222+
223+ // Add option using t.ts API - auto-detection handles boolean vs value options
224+ if ( handler ) {
225+ t . option ( argName , conf . description ?? '' , handler ) ;
226+ } else {
227+ t . option ( argName , conf . description ?? '' ) ;
228+ }
218229 }
219230 }
220231
0 commit comments