Skip to content
Myr

Merge pull request #208 from zxqfox/feature/descriptions-multiline-support

Before adoption: this commit came in with the history the project adopted, so no landing records it.

multiline descriptions support

authored by Randall Koutnik · committed by Randall Koutnik · parents e326d94, 4931c33 · Browse files · 6 files+83 added−6 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

6 files+83 added−6 removed

  • tests:+55 added−0 removed
  • other:+28 added−6 removed

6 files+83 added−6 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
added:test/test.command.description.js+27 added
added:test/test.command.usage.description.js+28 added
modified:index.js+23 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
5 unmodified lines
1046 for (var i = 0; i < options.length; i++) {1047 if (options[i] == '--help' || options[i] == '-h') {1048 cmd.outputHelp();1049 process.exit(0);10501051 // used for test flow only1052 options.splice(i, 1);1053 }1054 }1055}1056
15 unmodified lines
modified:package.json+2 added-1 removed
modified:Readme.md+2 added-1 removed
167 unmodified lines
168 -V, --version output the version number169 -p, --peppers Add peppers170 -P, --pineapple Add pineapple171 -b, --bbq Add bbq sauce172 -c, --cheese <type> Add the specified type of cheese [marble]172 -c, --cheese <type> Add the specified type173 of cheese [marble]174 -C, --no-cheese You do not want any cheese175176```177
135 unmodified lines