From 2bbef6caacb345df8da72bfa0b63f05e13549971 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Wed, 27 May 2026 02:49:20 -0400 Subject: [PATCH] fix: route nested root help targets --- src/cli/argv.test.ts | 15 +++++++++++++++ src/cli/argv.ts | 6 +++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/cli/argv.test.ts b/src/cli/argv.test.ts index 0dc1537f1c7..38a00f3af83 100644 --- a/src/cli/argv.test.ts +++ b/src/cli/argv.test.ts @@ -151,6 +151,21 @@ describe("argv helpers", () => { argv: ["node", "openclaw", "help", "--help"], expected: ["node", "openclaw", "help", "--help"], }, + { + name: "nested root help target", + argv: ["node", "openclaw", "help", "plugins", "list"], + expected: ["node", "openclaw", "plugins", "list", "--help"], + }, + { + name: "nested root help target with help flag", + argv: ["node", "openclaw", "help", "plugins", "list", "--help"], + expected: ["node", "openclaw", "plugins", "list", "--help"], + }, + { + name: "nested root help target with trailing root option", + argv: ["node", "openclaw", "help", "memory", "status", "--no-color"], + expected: ["node", "openclaw", "--no-color", "memory", "status", "--help"], + }, ])("normalizes root help targets: $name", ({ argv, expected }) => { expect(normalizeRootHelpTargetArgv(argv)).toEqual(expected); }); diff --git a/src/cli/argv.ts b/src/cli/argv.ts index 6012c9a9d29..58691b5c68c 100644 --- a/src/cli/argv.ts +++ b/src/cli/argv.ts @@ -245,13 +245,13 @@ export function normalizeRootHelpTargetArgv(argv: string[]): string[] { if ( help?.value !== "help" || !target || - positionals.length !== 2 || - (helpFlagIndex !== null && helpFlagIndex !== target.index + 1) + (helpFlagIndex !== null && helpFlagIndex !== positionals.at(-1)!.index + 1) ) { return argv; } - return [argv[0], argv[1], ...rootOptions, target.value, "--help"]; + const targetPath = positionals.slice(1).map((positional) => positional.value); + return [argv[0], argv[1], ...rootOptions, ...targetPath, "--help"]; } export function getFlagValue(argv: string[], name: string): string | null | undefined {