Skip to content

Commit 8c28a36

Browse files
committed
feat: consistently export same type for all entrypoints
Defines a `TabFunction` that all entrypoints export, such that we consistently support the same call signature.
1 parent 1d0beed commit 8c28a36

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

src/cac.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as fish from './fish';
44
import * as powershell from './powershell';
55
import type { CAC } from 'cac';
66
import { Completion } from './index';
7-
import { CompletionConfig, noopHandler } from './shared';
7+
import { noopHandler, TabFunction } from './shared';
88

99
const execPath = process.execPath;
1010
const 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
@@ -103,4 +100,6 @@ export default async function tab(
103100
});
104101

105102
return completion;
106-
}
103+
};
104+
105+
export default tab;

src/citty.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import type {
1111
SubCommandsDef,
1212
} from 'citty';
1313
import { generateFigSpec } from './fig';
14-
import { CompletionConfig, noopHandler } from './shared';
14+
import { CompletionConfig, noopHandler, TabFunction } from './shared';
1515

1616
function quoteIfNeeded(path: string) {
1717
return path.includes(' ') ? `'${path}'` : path;
@@ -92,10 +92,10 @@ 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 (
96+
instance,
97+
completionConfig
98+
) => {
9999
const completion = new Completion();
100100

101101
const meta = await resolve(instance.meta);
@@ -204,7 +204,9 @@ export default async function tab<TArgs extends ArgsDef>(
204204
subCommands.complete = completeCommand;
205205

206206
return completion;
207-
}
207+
};
208+
209+
export default tab;
208210

209211
type Resolvable<T> = T | Promise<T> | (() => T) | (() => Promise<T>);
210212

src/shared.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Handler } from './index';
1+
import { Handler, Completion } from './index';
22

33
export 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>;

0 commit comments

Comments
 (0)