MCPcopy
hub / github.com/tj/commander.js / helpCommand

Method helpCommand

lib/command.js:410–435  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

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.

Callers 7

addHelpCommandMethod · 0.95
_getHelpCommandMethod · 0.95
helpGroup.test.jsFile · 0.80
help-groups.jsFile · 0.80
index.test-d.tsFile · 0.80

Calls 6

_initCommandGroupMethod · 0.95
_getHelpCommandMethod · 0.95
createCommandMethod · 0.95
helpOptionMethod · 0.80
argumentsMethod · 0.80
descriptionMethod · 0.80

Tested by

no test coverage detected