@@ -11,8 +11,7 @@ import type {
1111} from 'citty' ;
1212import { generateFigSpec } from './fig' ;
1313import { CompletionConfig , assertDoubleDashes } from './shared' ;
14- import { OptionHandler , Command , Option , OptionsMap } from './t' ;
15- import t from './t' ;
14+ import t , { RootCommand } from './t' ;
1615
1716function quoteIfNeeded ( path : string ) {
1817 return path . includes ( ' ' ) ? `'${ path } '` : path ;
@@ -32,59 +31,6 @@ function isConfigPositional<T extends ArgsDef>(config: CommandDef<T>) {
3231 ) ;
3332}
3433
35- // Convert Handler from index.ts to OptionHandler from t.ts
36- function convertOptionHandler ( handler : any ) : OptionHandler {
37- return function (
38- this : Option ,
39- complete : ( value : string , description : string ) => void ,
40- options : OptionsMap ,
41- previousArgs ?: string [ ] ,
42- toComplete ?: string ,
43- endsWithSpace ?: boolean
44- ) {
45- // For short flags with equals sign and a value, don't complete (citty behavior)
46- // Check if this is a short flag option and if the toComplete looks like a value
47- if (
48- this . alias &&
49- toComplete &&
50- toComplete !== '' &&
51- ! toComplete . startsWith ( '-' )
52- ) {
53- // This might be a short flag with equals sign and a value
54- // Check if the previous args contain a short flag with equals sign
55- if ( previousArgs && previousArgs . length > 0 ) {
56- const lastArg = previousArgs [ previousArgs . length - 1 ] ;
57- if ( lastArg . includes ( '=' ) ) {
58- const [ flag , value ] = lastArg . split ( '=' ) ;
59- if ( flag . startsWith ( '-' ) && ! flag . startsWith ( '--' ) && value !== '' ) {
60- return ; // Don't complete short flags with equals sign and value
61- }
62- }
63- }
64- }
65-
66- // Call the old handler with the proper context
67- const result = handler (
68- previousArgs || [ ] ,
69- toComplete || '' ,
70- endsWithSpace || false
71- ) ;
72-
73- if ( Array . isArray ( result ) ) {
74- result . forEach ( ( item : any ) =>
75- complete ( item . value , item . description || '' )
76- ) ;
77- } else if ( result && typeof result . then === 'function' ) {
78- // Handle async handlers
79- result . then ( ( items : any [ ] ) => {
80- items . forEach ( ( item : any ) =>
81- complete ( item . value , item . description || '' )
82- ) ;
83- } ) ;
84- }
85- } ;
86- }
87-
8834async function handleSubCommands (
8935 subCommands : SubCommandsDef ,
9036 parentCmd ?: string ,
@@ -169,7 +115,7 @@ async function handleSubCommands(
169115export default async function tab < TArgs extends ArgsDef > (
170116 instance : CommandDef < TArgs > ,
171117 completionConfig ?: CompletionConfig
172- ) : Promise < any > {
118+ ) : Promise < RootCommand > {
173119 const meta = await resolve ( instance . meta ) ;
174120
175121 if ( ! meta ) {
0 commit comments