Merge pull request #397 from tj/revert-208-feature/descriptions-multiline-support
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Revert "multiline descriptions support" , please refer #396
authored by Zhiye Li · committed by Zhiye Li · parents 4dae21d, 9e7f2f6 · Browse files · 6 files·+6 added−82 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+6 added−82 removed
- tests:+0 added−55 removed
- other:+6 added−27 removed
Provenance
- Commit
64a5a5d- Tree
3a7e8bf- Author
Zhiye Li <zhiyelee@gmail.com>- Committer
Zhiye Li <zhiyelee@gmail.com>- Parent 1
4dae21d- Parent 2
9e7f2f6
6 files changed+6 added−82 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\nof cheese [marble]')15+ .option('-c, --cheese <type>', 'Add the specified type of 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 linesdeleted:test/test.command.description.js-27 removed
123456789101112131415161718192021222324252627var program = require('../') , sinon = require('sinon').sandbox.create() , should = require('should');
sinon.stub(process, 'exit');sinon.stub(process.stdout, 'write');
program .command('mycommand [options]', 'this is my command with\nmultiple lines in description.\nyay folks!');
program.parse(['node', 'mycommand', '--help']);
process.exit.calledOnce.should.be.true;process.exit.calledWith(0).should.be.true;
process.stdout.write.calledOnce.should.be.true;process.stdout.write.args.length.should.equal(1);
var output = process.stdout.write.args[0];
sinon.restore();
output[0].should.containEql([ ' mycommand [options] this is my command with', ' multiple lines in description.', ' yay folks!'].join('\n'));deleted:test/test.command.usage.description.js-28 removed
12345678910111213141516171819202122232425262728var program = require('../') , sinon = require('sinon').sandbox.create() , should = require('should');
sinon.stub(process, 'exit');sinon.stub(process.stdout, 'write');
program .command('cmd', 'usage doesn\'t work without description ;-(') .usage('[options] \\\n | xargs send --message \'yay folks!\' \\\n | wc -l');
program.parse(['node', 'cmd', '--help']);
process.exit.calledOnce.should.be.true;process.exit.calledWith(0).should.be.true;
process.stdout.write.calledOnce.should.be.true;process.stdout.write.args.length.should.equal(1);
var output = process.stdout.write.args[0];
sinon.restore();
output[0].should.containEql([ ' Usage: cmd [options] \\', ' | xargs send --message \'yay folks!\' \\', ' | wc -l'].join('\n'));modified:index.js+3 added-23 removed
909 unmodified lines910 911 // Prepend the help information912 return [pad('-h, --help', width) + ' ' + 'output usage information']913 .concat(this.options.map(function(option) {914- return pad(option.flags, width) + ' ' + offset(option.description, width + 2);914+ return pad(option.flags, width) + ' ' + option.description;915 }))916 .join('\n');917 };918 35 unmodified lines954 ''955 , ' Commands:'956 , ''957 , commands.map(function(cmd) {958- return pad(cmd[0], width) + ' ' + offset(cmd[1], width + 2);958+ return pad(cmd[0], width) + ' ' + cmd[1];959 }).join('\n').replace(/^/gm, ' ')960 , ''961 ].join('\n');962 };19 unmodified lines982 cmdName = cmdName + '|' + this._alias;983 }984 var usage = [985 ''986- ,' Usage: ' + cmdName + ' ' + offset(this.usage(), 9)986+ ,' Usage: ' + cmdName + ' ' + this.usage()987 , ''988 ];989 990 var cmds = [];65 unmodified lines1056 return str + Array(len + 1).join(' ');1057 }1058 1059 /**1060- * Prepend to each line of `str` spaced string of `offset` length.1061- *1062- * @param {String} str1063- * @param {Number} offset1064- * @param {Boolean} skipFirstLine1065- * @return {String}1066- * @api private1067- */1068-function offset(str, offset, skipFirstLine) {1069- var res = String(str || '').replace(/^/gm, pad('', offset));1070- if (!skipFirstLine) {1071- res = res.replace(/^\s+/, '');1072- }1073- return res;1074-}1075-1076-/**1060 * Output help information if necessary1061 *1062 * @param {Command} command to output help for1063 * @param {Array} array of options to search for -h or --help5 unmodified lines1069 for (var i = 0; i < options.length; i++) {1070 if (options[i] == '--help' || options[i] == '-h') {1071 cmd.outputHelp();1072 process.exit(0);1090-1091- // used for test flow only1092- options.splice(i, 1);1073 }1074 }1075 }1076 27 unmodified linesmodified:package.json+1 added-1 removed
13 unmodified lines1415161718181920212211 unmodified lines13 unmodified lines "url": "https://github.com/tj/commander.js.git" }, "devDependencies": { "should": ">= 0.0.1", "sinon": ">= 1.13.0" "sinon": ">= 1.14.1" }, "scripts": { "test": "make test" },11 unmodified linesmodified:Readme.md+1 added-2 removed
198 unmodified lines199 -V, --version output the version number200 -p, --peppers Add peppers201 -P, --pineapple Add pineapple202 -b, --bbq Add bbq sauce203- -c, --cheese <type> Add the specified type204- of cheese [marble]203+ -c, --cheese <type> Add the specified type of cheese [marble]204 -C, --no-cheese You do not want any cheese205 206 ```207 135 unmodified lines