Descriptions: support multiline strings
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Fixes #207 Closes gh-208
authored by Alexej Yaroshevich · committed by Alexej Yaroshevich · parent 5a15a34 · Browse files · 3 files·+23 added−5 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+23 added−5 removed
- other:+23 added−5 removed
Provenance
- Commit
d679feb- Tree
cce2dad- Author
Alexej Yaroshevich <alex@qfox.ru>- Committer
Alexej Yaroshevich <alex@qfox.ru>- Parent
5a15a34
3 files changed+23 added−5 removed
modified:examples/pizza+1 added-1 removed
10 unmodified lines11 .description('An application for pizzas ordering')12 .option('-p, --peppers', 'Add peppers')13 .option('-P, --pineapple', 'Add pineapple')14 .option('-b, --bbq', 'Add bbq sauce')15- .option('-c, --cheese <type>', 'Add the specified type of cheese [marble]')15+ .option('-c, --cheese <type>', 'Add the specified type\nof cheese [marble]')16 .option('-C, --no-cheese', 'You do not want any cheese')17 .parse(process.argv);18 19 console.log('you ordered a pizza with:');10 unmodified linesmodified:index.js+20 added-3 removed
871 unmodified lines872 873 // Prepend the help information874 return [pad('-h, --help', width) + ' ' + 'output usage information']875 .concat(this.options.map(function(option) {876- return pad(option.flags, width) + ' ' + option.description;876+ return pad(option.flags, width) + ' ' + offset(option.description, width + 2);877 }))878 .join('\n');879 };880 33 unmodified lines914 ''915 , ' Commands:'916 , ''917 , commands.map(function(cmd) {918- return pad(cmd[0], width) + ' ' + cmd[1];918+ return pad(cmd[0], width) + ' ' + offset(cmd[1], width + 2);919 }).join('\n').replace(/^/gm, ' ')920 , ''921 ].join('\n');922 };19 unmodified lines942 cmdName = cmdName + '|' + this._alias;943 }944 var usage = [945 ''946- ,' Usage: ' + cmdName + ' ' + this.usage()946+ ,' Usage: ' + cmdName + ' ' + offset(this.usage(), 9)947 , ''948 ];949 950 var cmds = [];65 unmodified lines1016 return str + Array(len + 1).join(' ');1017 }1018 1019 /**1020+ * Prepend to each line of `str` spaced string of `offset` length.1021+ *1022+ * @param {String} str1023+ * @param {Number} offset1024+ * @param {Boolean} skipFirstLine1025+ * @return {String}1026+ * @api private1027+ */1028+function offset(str, offset, skipFirstLine) {1029+ var res = String(str || '').replace(/^/gm, pad('', offset));1030+ if (!skipFirstLine) {1031+ res = res.replace(/^\s+/, '');1032+ }1033+ return res;1034+}1035+1036+/**1037 * Output help information if necessary1038 *1039 * @param {Command} command to output help for1040 * @param {Array} array of options to search for -h or --help28 unmodified linesmodified:Readme.md+2 added-1 removed
165 unmodified lines166 -V, --version output the version number167 -p, --peppers Add peppers168 -P, --pineapple Add pineapple169 -b, --bbq Add bbq sauce170- -c, --cheese <type> Add the specified type of cheese [marble]170+ -c, --cheese <type> Add the specified type171+ of cheese [marble]172 -C, --no-cheese You do not want any cheese173 174 ```175 155 unmodified lines