Files
openclaw/src/cli/program/parent-default-help.ts
hclsys ba80695bba fix(cli): exit 0 when invoking parent commands without a subcommand (#73077)
Several `openclaw <parent>` commands (channels, plugins, approvals, devices,
cron, mcp) were exiting with code 1 when invoked bare, while printing the
same help-style content that `<parent> --help` produces (which exits 0).
This broke `&&` chains and surfaced a misleading
`ELIFECYCLE Command failed with exit code 1.` line under pnpm.

Add a small `applyParentDefaultHelpAction(cmd)` helper in
`src/cli/program/parent-default-help.ts` that attaches a default action
which prints the parent's own help and sets `process.exitCode = 0`. The
helper is a no-op when the parent already has its own action (e.g.
`agents` defaulting to `agents list`), so existing intentional defaults
are preserved.

Apply it to the six core parents listed in #73077.
2026-04-28 02:40:44 +01:00

23 lines
906 B
TypeScript

import type { Command } from "commander";
/**
* Wire a parent command so that invoking it without a subcommand prints the
* parent's own help and exits with status `0`.
*
* Commander's default behavior for a parent with subcommands is to print help
* and set `process.exitCode = 1`, which differs from `<parent> --help` (which
* exits 0). That asymmetry breaks shell `&&` chains and surfaces a misleading
* `ELIFECYCLE Command failed with exit code 1.` line for users running through
* pnpm. See #73077.
*
* Apply this helper only to parent commands that do not have their own default
* action. Commander does not expose a public "has action handler" API, so
* callers keep that ownership explicit instead of probing private internals.
*/
export function applyParentDefaultHelpAction(parent: Command): void {
parent.action(() => {
parent.outputHelp();
process.exitCode = 0;
});
}