fix(cli): fast-path bare channels help (#77659)

* fix(cli): fast-path bare channels help

* fix(cli): normalize channels add argv gating

* fix(cli): restore channel add completion flags
This commit is contained in:
Vincent Koc
2026-05-05 16:02:39 -07:00
committed by GitHub
parent 1e1903487f
commit fdddb413ef
16 changed files with 319 additions and 48 deletions

View File

@@ -1,5 +1,21 @@
import type { Command } from "commander";
const parentDefaultHelpCommands = new WeakSet<Command>();
function outputParentHelpWithoutStartupBanner(parent: Command): void {
const previous = process.env.OPENCLAW_SUPPRESS_HELP_BANNER;
process.env.OPENCLAW_SUPPRESS_HELP_BANNER = "1";
try {
parent.outputHelp();
} finally {
if (previous === undefined) {
delete process.env.OPENCLAW_SUPPRESS_HELP_BANNER;
} else {
process.env.OPENCLAW_SUPPRESS_HELP_BANNER = previous;
}
}
}
/**
* Wire a parent command so that invoking it without a subcommand prints the
* parent's own help and exits with status `0`.
@@ -15,8 +31,13 @@ import type { Command } from "commander";
* callers keep that ownership explicit instead of probing private internals.
*/
export function applyParentDefaultHelpAction(parent: Command): void {
parentDefaultHelpCommands.add(parent);
parent.action(() => {
parent.outputHelp();
outputParentHelpWithoutStartupBanner(parent);
process.exitCode = 0;
});
}
export function isParentDefaultHelpAction(parent: Command): boolean {
return parentDefaultHelpCommands.has(parent);
}