MCPcopy
hub / github.com/jsdoc/jsdoc / formatHelpInfo

Function formatHelpInfo

lib/jsdoc/opts/argparser.js:50–84  ·  view source on GitHub ↗
({names, descriptions})

Source from the content-addressed store, hash-verified

48// | -f, --foo Very long description very long description very long |
49// | description very long description. |
50function formatHelpInfo({names, descriptions}) {
51 const MARGIN_LENGTH = 4;
52 const results = [];
53
54 const maxLength = process.stdout.columns;
55 const maxNameLength = findMaxLength(names);
56 const wrapDescriptionAt = maxLength - (MARGIN_LENGTH * 3) - maxNameLength;
57
58 // build the string for each option
59 names.forEach((name, i) => {
60 let result;
61 let partialDescription;
62 let words;
63
64 // add a left margin to the name
65 result = padLeft(names[i], MARGIN_LENGTH);
66 // and a right margin, with extra padding so the descriptions line up with one another
67 result = padRight(result, maxNameLength - names[i].length + MARGIN_LENGTH);
68
69 // split the description on spaces
70 words = descriptions[i].split(' ');
71 // add as much of the description as we can fit on the first line
72 result += concatWithMaxLength(words, wrapDescriptionAt);
73 // if there's anything left, keep going until we've consumed the description
74 while (words.length) {
75 partialDescription = padding( maxNameLength + (MARGIN_LENGTH * 2) );
76 partialDescription += concatWithMaxLength(words, wrapDescriptionAt);
77 result += `\n${partialDescription}`;
78 }
79
80 results.push(result);
81 });
82
83 return results;
84}
85
86/**
87 * A parser to interpret the key-value pairs entered on the command line.

Callers 1

helpMethod · 0.85

Calls 5

findMaxLengthFunction · 0.85
padLeftFunction · 0.85
padRightFunction · 0.85
concatWithMaxLengthFunction · 0.85
paddingFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…