diff --git a/src/cli/command-registration-policy.ts b/src/cli/command-registration-policy.ts index 638e87693eb..efef8b7844a 100644 --- a/src/cli/command-registration-policy.ts +++ b/src/cli/command-registration-policy.ts @@ -14,11 +14,12 @@ export function shouldSkipPluginCommandRegistration(params: { if (params.hasBuiltinPrimary) { return true; } - if (params.primary === "help" && resolveCliArgvInvocation(params.argv).hasHelpOrVersion) { - return true; + const invocation = resolveCliArgvInvocation(params.argv); + if (params.primary === "help") { + return invocation.hasHelpOrVersion && invocation.commandPath.length <= 1; } if (!params.primary) { - return resolveCliArgvInvocation(params.argv).hasHelpOrVersion; + return invocation.hasHelpOrVersion; } return false; } diff --git a/src/cli/program/command-group-descriptors.ts b/src/cli/program/command-group-descriptors.ts index 11f46a64d3c..cb37dfc0935 100644 --- a/src/cli/program/command-group-descriptors.ts +++ b/src/cli/program/command-group-descriptors.ts @@ -1,5 +1,4 @@ import type { Command } from "commander"; -import type { CommandGroupEntry } from "./register-command-groups.js"; export type NamedCommandDescriptor = { name: string; @@ -23,6 +22,11 @@ export type ResolvedCommandGroupEntry Promise | void; +}; + function buildDescriptorIndex( descriptors: readonly TDescriptor[], ): Map { @@ -49,8 +53,8 @@ export function resolveCommandGroupEntries( descriptors: readonly NamedCommandDescriptor[], specs: readonly CommandGroupDescriptorSpec[], - mapRegister: (register: TRegister) => CommandGroupEntry["register"], -): CommandGroupEntry[] { + mapRegister: (register: TRegister) => CommandGroupEntryLike["register"], +): CommandGroupEntryLike[] { return resolveCommandGroupEntries(descriptors, specs).map((entry) => ({ placeholders: entry.placeholders, register: mapRegister(entry.register), diff --git a/src/cli/program/root-help.test.ts b/src/cli/program/root-help.test.ts index 303ecda87b2..869ba8a3c4f 100644 --- a/src/cli/program/root-help.test.ts +++ b/src/cli/program/root-help.test.ts @@ -12,6 +12,13 @@ const getPluginCliCommandDescriptorsMock = vi.fn( ); vi.mock("./core-command-descriptors.js", () => ({ + CORE_CLI_COMMAND_DESCRIPTORS: [ + { + name: "status", + description: "Show status", + hasSubcommands: false, + }, + ], getCoreCliCommandDescriptors: () => [ { name: "status", @@ -23,6 +30,13 @@ vi.mock("./core-command-descriptors.js", () => ({ })); vi.mock("./subcli-descriptors.js", () => ({ + SUB_CLI_DESCRIPTORS: [ + { + name: "config", + description: "Manage config", + hasSubcommands: true, + }, + ], getSubCliEntries: () => [ { name: "config",