File tree Expand file tree Collapse file tree 3 files changed +14
-11
lines changed Expand file tree Collapse file tree 3 files changed +14
-11
lines changed Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ import * as fish from './fish';
44import * as powershell from './powershell' ;
55import type { CAC } from 'cac' ;
66import { Completion } from './index' ;
7- import { CompletionConfig , noopHandler } from './shared' ;
7+ import { noopHandler , TabFunction } from './shared' ;
88
99const execPath = process . execPath ;
1010const processArgs = process . argv . slice ( 1 ) ;
@@ -18,10 +18,7 @@ function quoteIfNeeded(path: string): string {
1818 return path . includes ( ' ' ) ? `'${ path } '` : path ;
1919}
2020
21- export default async function tab (
22- instance : CAC ,
23- completionConfig ?: CompletionConfig
24- ) {
21+ const tab : TabFunction < CAC > = async ( instance , completionConfig ) => {
2522 const completion = new Completion ( ) ;
2623
2724 // Add all commands and their options
@@ -104,3 +101,5 @@ export default async function tab(
104101
105102 return completion ;
106103}
104+
105+ export default tab ;
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ import type {
1111 SubCommandsDef ,
1212} from 'citty' ;
1313import { generateFigSpec } from './fig' ;
14- import { CompletionConfig , noopHandler } from './shared' ;
14+ import { CompletionConfig , noopHandler , TabFunction } from './shared' ;
1515
1616function quoteIfNeeded ( path : string ) {
1717 return path . includes ( ' ' ) ? `'${ path } '` : path ;
@@ -92,10 +92,7 @@ async function handleSubCommands(
9292 }
9393}
9494
95- export default async function tab < TArgs extends ArgsDef > (
96- instance : CommandDef < TArgs > ,
97- completionConfig ?: CompletionConfig
98- ) {
95+ const tab : TabFunction < CommandDef < ArgsDef > > = async ( instance , completionConfig ) => {
9996 const completion = new Completion ( ) ;
10097
10198 const meta = await resolve ( instance . meta ) ;
@@ -206,6 +203,8 @@ export default async function tab<TArgs extends ArgsDef>(
206203 return completion ;
207204}
208205
206+ export default tab ;
207+
209208type Resolvable < T > = T | Promise < T > | ( ( ) => T ) | ( ( ) => Promise < T > ) ;
210209
211210async function resolve < T > ( resolvable : Resolvable < T > ) : Promise < T > {
Original file line number Diff line number Diff line change 1- import { Handler } from './index' ;
1+ import { Handler , Completion } from './index' ;
22
33export const noopHandler : Handler = ( ) => {
44 return [ ] ;
@@ -16,3 +16,8 @@ export interface CompletionConfig {
1616 }
1717 > ;
1818}
19+
20+ export type TabFunction < T > = (
21+ instance : T ,
22+ completionConfig ?: CompletionConfig
23+ ) => Promise < Completion > ;
You can’t perform that action at this time.
0 commit comments