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

Method formatHelp

lib/help.js:444–528  ·  view source on GitHub ↗

* Generate the built-in help text. * * @param {Command} cmd * @param {Help} helper * @returns {string}

(cmd, helper)

Source from the content-addressed store, hash-verified

442 */
443
444 formatHelp(cmd, helper) {
445 const termWidth = helper.padWidth(cmd, helper);
446 const helpWidth = helper.helpWidth ?? 80; // in case prepareContext() was not called
447
448 function callFormatItem(term, description) {
449 return helper.formatItem(term, termWidth, description, helper);
450 }
451
452 // Usage
453 let output = [
454 `${helper.styleTitle('Usage:')} ${helper.styleUsage(helper.commandUsage(cmd))}`,
455 '',
456 ];
457
458 // Description
459 const commandDescription = helper.commandDescription(cmd);
460 if (commandDescription.length > 0) {
461 output = output.concat([
462 helper.boxWrap(
463 helper.styleCommandDescription(commandDescription),
464 helpWidth,
465 ),
466 '',
467 ]);
468 }
469
470 // Arguments
471 const argumentList = helper.visibleArguments(cmd).map((argument) => {
472 return callFormatItem(
473 helper.styleArgumentTerm(helper.argumentTerm(argument)),
474 helper.styleArgumentDescription(helper.argumentDescription(argument)),
475 );
476 });
477 output = output.concat(
478 this.formatItemList('Arguments:', argumentList, helper),
479 );
480
481 // Options
482 const optionGroups = this.groupItems(
483 cmd.options,
484 helper.visibleOptions(cmd),
485 (option) => option.helpGroupHeading ?? 'Options:',
486 );
487 optionGroups.forEach((options, group) => {
488 const optionList = options.map((option) => {
489 return callFormatItem(
490 helper.styleOptionTerm(helper.optionTerm(option)),
491 helper.styleOptionDescription(helper.optionDescription(option)),
492 );
493 });
494 output = output.concat(this.formatItemList(group, optionList, helper));
495 });
496
497 if (helper.showGlobalOptions) {
498 const globalOptionList = helper
499 .visibleGlobalOptions(cmd)
500 .map((option) => {
501 return callFormatItem(

Callers 1

helpInformationMethod · 0.45

Calls 15

formatItemListMethod · 0.95
groupItemsMethod · 0.95
padWidthMethod · 0.80
styleUsageMethod · 0.80
commandUsageMethod · 0.80
commandDescriptionMethod · 0.80
visibleArgumentsMethod · 0.80
styleArgumentTermMethod · 0.80
argumentTermMethod · 0.80
argumentDescriptionMethod · 0.80
visibleOptionsMethod · 0.80

Tested by

no test coverage detected