* Customise or override default help command. By default a help command is automatically added if your command has subcommands. * * @example * program.helpCommand('help [cmd]'); * program.helpCommand('help [cmd]', 'show help'); * program.helpCommand(false); // suppress defaul
(enableOrNameAndArgs, description)
| 408 | */ |
| 409 | |
| 410 | helpCommand(enableOrNameAndArgs, description) { |
| 411 | if (typeof enableOrNameAndArgs === 'boolean') { |
| 412 | this._addImplicitHelpCommand = enableOrNameAndArgs; |
| 413 | if (enableOrNameAndArgs && this._defaultCommandGroup) { |
| 414 | // make the command to store the group |
| 415 | this._initCommandGroup(this._getHelpCommand()); |
| 416 | } |
| 417 | return this; |
| 418 | } |
| 419 | |
| 420 | const nameAndArgs = enableOrNameAndArgs ?? 'help [command]'; |
| 421 | const [, helpName, helpArgs] = nameAndArgs.match(/([^ ]+) *(.*)/); |
| 422 | const helpDescription = description ?? 'display help for command'; |
| 423 | |
| 424 | const helpCommand = this.createCommand(helpName); |
| 425 | helpCommand.helpOption(false); |
| 426 | if (helpArgs) helpCommand.arguments(helpArgs); |
| 427 | if (helpDescription) helpCommand.description(helpDescription); |
| 428 | |
| 429 | this._addImplicitHelpCommand = true; |
| 430 | this._helpCommand = helpCommand; |
| 431 | // init group unless lazy create |
| 432 | if (enableOrNameAndArgs || description) this._initCommandGroup(helpCommand); |
| 433 | |
| 434 | return this; |
| 435 | } |
| 436 | |
| 437 | /** |
| 438 | * Add prepared custom help command. |
no test coverage detected