-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathcommands.ts
More file actions
58 lines (50 loc) · 1.83 KB
/
commands.ts
File metadata and controls
58 lines (50 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import type { Command } from '@commander-js/extra-typings';
export interface CommandMeta {
id: string;
title: string;
description: string;
subcommands: string[];
disabled?: boolean;
cliOnly: boolean;
}
/**
* Commands hidden from TUI entirely (meta commands).
*/
const HIDDEN_FROM_TUI = ['help', 'telemetry'] as const;
/**
* Commands that are CLI-only (shown but marked as requiring CLI invocation).
*/
const CLI_ONLY_COMMANDS = ['logs', 'traces', 'pause', 'resume'] as const;
/**
* Commands hidden from TUI when inside an existing project.
* 'create' is hidden because users should use 'add' instead.
*/
const HIDDEN_WHEN_IN_PROJECT = ['create'] as const;
/**
* Subcommands hidden from TUI suggestions.
* These are registered with { hidden: true } in commander but we track them
* here since commander doesn't expose a public API to check hidden status.
*/
const HIDDEN_SUBCOMMANDS = ['gateway', 'gateway-target'] as const;
interface GetCommandsOptions {
/** Whether user is currently inside an AgentCore project */
inProject?: boolean;
}
export function getCommandsForUI(program: Command, options: GetCommandsOptions = {}): CommandMeta[] {
const { inProject = false } = options;
return program.commands
.filter(cmd => !HIDDEN_FROM_TUI.includes(cmd.name() as (typeof HIDDEN_FROM_TUI)[number]))
.filter(
cmd => !inProject || !HIDDEN_WHEN_IN_PROJECT.includes(cmd.name() as (typeof HIDDEN_WHEN_IN_PROJECT)[number])
)
.map(cmd => ({
id: cmd.name(),
title: cmd.name(),
description: cmd.description(),
subcommands: cmd.commands
.filter(sub => !HIDDEN_SUBCOMMANDS.includes(sub.name() as (typeof HIDDEN_SUBCOMMANDS)[number]))
.map(sub => sub.name()),
disabled: false,
cliOnly: CLI_ONLY_COMMANDS.includes(cmd.name() as (typeof CLI_ONLY_COMMANDS)[number]),
}));
}