({names, descriptions})
| 48 | // | -f, --foo Very long description very long description very long | |
| 49 | // | description very long description. | |
| 50 | function 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. |
no test coverage detected
searching dependent graphs…