fix: route nested root help targets

This commit is contained in:
Peter Steinberger
2026-05-27 02:49:20 -04:00
parent 5f6293a902
commit 2bbef6caac
2 changed files with 18 additions and 3 deletions

View File

@@ -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);
});

View File

@@ -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 {