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

Method outputHelp

lib/command.js:2519–2558  ·  view source on GitHub ↗

* Output help information for this command. * * Outputs built-in help, and custom text added using `.addHelpText()`. * * @param {{ error: boolean } | Function} [contextOptions] - pass {error:true} to write to stderr instead of stdout

(contextOptions)

Source from the content-addressed store, hash-verified

2517 */
2518
2519 outputHelp(contextOptions) {
2520 let deprecatedCallback;
2521 if (typeof contextOptions === 'function') {
2522 deprecatedCallback = contextOptions;
2523 contextOptions = undefined;
2524 }
2525
2526 const outputContext = this._getOutputContext(contextOptions);
2527 /** @type {HelpTextEventContext} */
2528 const eventContext = {
2529 error: outputContext.error,
2530 write: outputContext.write,
2531 command: this,
2532 };
2533
2534 this._getCommandAndAncestors()
2535 .reverse()
2536 .forEach((command) => command.emit('beforeAllHelp', eventContext));
2537 this.emit('beforeHelp', eventContext);
2538
2539 let helpInformation = this.helpInformation({ error: outputContext.error });
2540 if (deprecatedCallback) {
2541 helpInformation = deprecatedCallback(helpInformation);
2542 if (
2543 typeof helpInformation !== 'string' &&
2544 !Buffer.isBuffer(helpInformation)
2545 ) {
2546 throw new Error('outputHelp callback must return a string or a Buffer');
2547 }
2548 }
2549 outputContext.write(helpInformation);
2550
2551 if (this._getHelpOption()?.long) {
2552 this.emit(this._getHelpOption().long); // deprecated
2553 }
2554 this.emit('afterHelp', eventContext);
2555 this._getCommandAndAncestors().forEach((command) =>
2556 command.emit('afterAllHelp', eventContext),
2557 );
2558 }
2559
2560 /**
2561 * You can pass in flags and a description to customise the built-in help option.

Callers 8

errorMethod · 0.95
helpMethod · 0.95
help.style.test.jsFile · 0.80
index.test-d.tsFile · 0.80

Calls 5

_getOutputContextMethod · 0.95
helpInformationMethod · 0.95
_getHelpOptionMethod · 0.95
writeMethod · 0.80

Tested by

no test coverage detected