Skip to content

Commit 1e2408c

Browse files
authored
refactor(cli): share completion metadata helpers (#133046)
1 parent af7c655 commit 1e2408c

2 files changed

Lines changed: 6 additions & 12 deletions

File tree

‎src/cli/completion-cli.ts‎

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import { routeLogsToStderr } from "../logging/console.js";
77
import { formatConsoleDiagnosticLine } from "../logging/json-console-line.js";
88
import {
99
collectShellCompletionCommandTree,
10+
commandNameVariants,
11+
completionFlags,
1012
type ShellCompletionContext,
1113
} from "./completion-command-tree.js";
1214
import {
@@ -41,10 +43,6 @@ export function getCompletionScript(shell: CompletionShell, program: Command): s
4143
return generateFishCompletion(program);
4244
}
4345

44-
function completionFlags(option: Option): string[] {
45-
return [option.short, option.long].filter((flag): flag is string => Boolean(flag));
46-
}
47-
4846
function preferredCompletionFlag(option: Option): string {
4947
return option.long ?? option.short ?? option.flags;
5048
}
@@ -53,12 +51,6 @@ function fishWords(values: readonly string[]): string {
5351
return values.join(" ");
5452
}
5553

56-
// Aliases are typeable command words; every completion surface must offer them
57-
// alongside the canonical name or advertised commands appear nonexistent.
58-
function commandNameVariants(cmd: Command): string[] {
59-
return [cmd.name(), ...cmd.aliases()];
60-
}
61-
6254
function generateFishPathHelper(rootCmd: string, contexts: ShellCompletionContext[]): string {
6355
const knownCommandPaths = contexts
6456
.flatMap((context) => context.pathVariants)

‎src/cli/completion-command-tree.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@ type ShellCompletionCommandTree = {
1919
descendants: ShellCompletionContext[];
2020
};
2121

22-
function completionFlags(option: Option): string[] {
22+
export function completionFlags(option: Option): string[] {
2323
return [option.short, option.long].filter((flag): flag is string => Boolean(flag));
2424
}
2525

26-
function commandNameVariants(command: Command): string[] {
26+
// Aliases are typeable command words; every completion surface must offer them
27+
// alongside the canonical name or advertised commands appear nonexistent.
28+
export function commandNameVariants(command: Command): string[] {
2729
return [command.name(), ...command.aliases()];
2830
}
2931

0 commit comments

Comments
 (0)