22import { Command , type ErrorOptions } from "commander" ;
33import { 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
1714export 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}
0 commit comments