Skip to content

Commit

Permalink
Add new helpCommand and update addHelpCommand (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
shadowspawn authored Jan 17, 2024
1 parent fe6c997 commit 5e21c6f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
25 changes: 18 additions & 7 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -586,22 +586,33 @@ export class CommanderError extends Error {
* @returns `this` command for chaining
*/
arguments<Names extends string>(args: Names): Command<[...Args, ...InferArguments<Names>], Opts>;


/**
* Override default decision whether to add implicit help command.
* Customise or override default help command. By default a help command is automatically added if your command has subcommands.
*
* @example
* ```ts
* program.helpCommand('help [cmd]');
* program.helpCommand('help [cmd]', 'show help');
* program.helpCommand(false); // suppress default help command
* program.helpCommand(true); // add help command even if no subcommands
* ```
* addHelpCommand() // force on
* addHelpCommand(false); // force off
* addHelpCommand('help [cmd]', 'display help for [cmd]'); // force on with custom details
* ```
*/
helpCommand(nameAndArgs: string, description?: string): this;
helpCommand(enable: boolean): this;

/**
* Add prepared custom help command.
*
* @returns `this` command for chaining
*/
addHelpCommand(enableOrNameAndArgs?: string | boolean, description?: string): this;

addHelpCommand(cmd: Command): this;
/** @deprecated since v12, instead use helpCommand */
addHelpCommand(nameAndArgs: string, description?: string): this;
/** @deprecated since v12, instead use helpCommand */
addHelpCommand(enable?: boolean): this;

/**
* Add hook for life cycle event.
*/
Expand Down
18 changes: 13 additions & 5 deletions tests/commander.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,19 @@ expectChainedCommand(program.argument('[value]', 'description', parseFloat, 1.23
expectChainedCommand(program.arguments('<cmd> [env]'));

// addHelpCommand
expectChainedCommand(program.addHelpCommand());
expectChainedCommand(program.addHelpCommand(false));
expectChainedCommand(program.addHelpCommand(true));
expectChainedCommand(program.addHelpCommand('compress <file>'));
expectChainedCommand(program.addHelpCommand('compress <file>', 'compress target file'));
expectType<commander.Command>(program.addHelpCommand(new commander.Command('assist')));
// Deprecated uses
expectType<commander.Command>(program.addHelpCommand());
expectType<commander.Command>(program.addHelpCommand(false));
expectType<commander.Command>(program.addHelpCommand(true));
expectType<commander.Command>(program.addHelpCommand('assist [cmd]'));
expectType<commander.Command>(program.addHelpCommand('assist [file]', 'display help'));

// helpCommand
expectType<commander.Command>(program.helpCommand(false));
expectType<commander.Command>(program.helpCommand(true));
expectType<commander.Command>(program.helpCommand('assist [cmd]'));
expectType<commander.Command>(program.helpCommand('assist [file]', 'display help'));

// exitOverride
expectChainedCommand(program.exitOverride());
Expand Down

0 comments on commit 5e21c6f

Please sign in to comment.