Skip to content

Commit 5689d83

Browse files
committed
refactor(cli): delegate the Commander help hook through super
1 parent 97077bc commit 5689d83

2 files changed

Lines changed: 12 additions & 13 deletions

File tree

‎src/cli/program/openclaw-command.ts‎

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,14 @@
22
import { Command, type ErrorOptions } from "commander";
33
import { getCommanderSubcommandFact, setCommanderErrorCommand } from "./commander-parse-facts.js";
44

5-
type CommanderHelpInternals = Command & {
6-
_outputHelpIfRequested(args: string[]): void;
7-
};
8-
9-
/* oxlint-disable eslint/no-underscore-dangle -- The identifier is Commander 15.0.0's own hook name; package.json pins that exact version. */
10-
/* oxlint-disable typescript/unbound-method -- Commander omits the hook from its types; the call site restores the receiver. */
11-
// SAFETY: Commander 15.0.0's runtime class defines this pinned private hook with the signature exposed above.
12-
const commanderOutputHelpIfRequested = (Command.prototype as CommanderHelpInternals)
13-
._outputHelpIfRequested;
14-
/* oxlint-enable typescript/unbound-method */
15-
/* oxlint-enable eslint/no-underscore-dangle */
5+
// Commander 15 declares this help hook only in its runtime class, not its types.
6+
// Declaring it here lets the subclass override and delegate through `super`
7+
// instead of re-binding a captured prototype method.
8+
declare module "commander" {
9+
interface Command {
10+
_outputHelpIfRequested(args: string[]): void;
11+
}
12+
}
1613

1714
export class OpenClawCommand extends Command {
1815
override createCommand(name?: string): Command {
@@ -30,7 +27,7 @@ export class OpenClawCommand extends Command {
3027

3128
// Commander 15 checks this internal hook before dispatching actions.
3229
// Defer only marked lazy placeholders so their real command tree can decide.
33-
_outputHelpIfRequested(args: string[]): void {
30+
override _outputHelpIfRequested(args: string[]): void {
3431
const subcommandFact = getCommanderSubcommandFact(this, args);
3532
if (subcommandFact?.kind === "defer") {
3633
return;
@@ -40,6 +37,7 @@ export class OpenClawCommand extends Command {
4037
code: "commander.unknownCommand",
4138
});
4239
}
43-
commanderOutputHelpIfRequested.call(this, args);
40+
// oxlint-disable-next-line eslint/no-underscore-dangle -- Commander 15.0.0 owns this hook name; package.json pins that exact version.
41+
super._outputHelpIfRequested(args);
4442
}
4543
}

‎test/scripts/lint-suppressions.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ describe("production lint suppressions", () => {
208208
"src/cli/cli-utils.ts|typescript/no-unnecessary-type-parameters|1",
209209
"src/cli/command-options.ts|typescript/no-unnecessary-type-parameters|1",
210210
"src/cli/plugins-cli-test-helpers.ts|typescript/no-unnecessary-type-parameters|1",
211+
"src/cli/program/openclaw-command.ts|eslint/no-underscore-dangle|1",
211212
"src/cli/test-runtime-capture.ts|typescript/no-unnecessary-type-parameters|1",
212213
"src/gateway/test-helpers.server.ts|typescript/no-unnecessary-type-parameters|1",
213214
"src/hooks/module-loader.ts|typescript/no-unnecessary-type-parameters|1",

0 commit comments

Comments
 (0)