Skip to content
Myr

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

3 files+23 added−5 removed

modified:examples/pizza+1 added-1 removed
10 unmodified lines
11 .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);1819console.log('you ordered a pizza with:');
10 unmodified lines
modified:index.js+20 added-3 removed
871 unmodified lines
872873 // 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 lines
914 ''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 lines
942 cmdName = cmdName + '|' + this._alias;943 }944 var usage = [945 ''946 ,' Usage: ' + cmdName + ' ' + this.usage()946 ,' Usage: ' + cmdName + ' ' + offset(this.usage(), 9)947 , ''948 ];949950 var cmds = [];
65 unmodified lines
1016 return str + Array(len + 1).join(' ');1017}10181019/**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 */1028function 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}10351036/**1037 * Output help information if necessary1038 *1039 * @param {Command} command to output help for1040 * @param {Array} array of options to search for -h or --help
28 unmodified lines
modified:Readme.md+2 added-1 removed
165 unmodified lines
166 -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 cheese173174```175
155 unmodified lines