fix: mark plugin command groups in root help

This commit is contained in:
Peter Steinberger
2026-05-27 02:49:40 -04:00
parent 2bbef6caac
commit 482018e536
3 changed files with 28 additions and 9 deletions

View File

@@ -43,7 +43,16 @@ const EXAMPLES = [
],
] as const;
export function configureProgramHelp(program: Command, ctx: ProgramContext) {
export function configureProgramHelp(
program: Command,
ctx: ProgramContext,
options?: { commandsWithSubcommands?: ReadonlySet<string> },
) {
const commandsWithSubcommands = new Set([
...ROOT_COMMANDS_WITH_SUBCOMMANDS,
...(options?.commandsWithSubcommands ?? []),
]);
program
.name(CLI_NAME)
.description("")
@@ -77,7 +86,7 @@ export function configureProgramHelp(program: Command, ctx: ProgramContext) {
optionTerm: (option) => theme.option(option.flags),
subcommandTerm: (cmd) => {
const isRootCommand = cmd.parent === program;
const hasSubcommands = isRootCommand && ROOT_COMMANDS_WITH_SUBCOMMANDS.has(cmd.name());
const hasSubcommands = isRootCommand && commandsWithSubcommands.has(cmd.name());
return theme.command(hasSubcommands ? `${cmd.name()} *` : cmd.name());
},
});

View File

@@ -80,6 +80,7 @@ describe("root help", () => {
expect(text).toContain("status");
expect(text).toContain("config");
expect(text).toContain("matrix");
expect(text).toContain("matrix *");
expect(text).toContain("Matrix channel utilities");
});

View File

@@ -19,19 +19,28 @@ export type RootHelpRenderOptions = Pick<PluginLoadOptions, "pluginSdkResolution
async function buildRootHelpProgram(renderOptions?: RootHelpRenderOptions): Promise<Command> {
const program = new Command();
configureProgramHelp(program, {
programVersion: VERSION,
channelOptions: [],
messageChannelOptions: "",
agentChannelOptions: "",
});
const pluginDescriptors =
renderOptions?.includePluginDescriptors === true || renderOptions?.config
? await getPluginCliCommandDescriptors(renderOptions.config, renderOptions.env, {
pluginSdkResolution: renderOptions.pluginSdkResolution,
})
: [];
configureProgramHelp(
program,
{
programVersion: VERSION,
channelOptions: [],
messageChannelOptions: "",
agentChannelOptions: "",
},
{
commandsWithSubcommands: new Set(
pluginDescriptors
.filter((descriptor) => descriptor.hasSubcommands)
.map((descriptor) => descriptor.name),
),
},
);
addCommandDescriptorsToProgram(
program,