Merge branch 'master' into fix-global
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by zhiyelee · committed by zhiyelee · parents 30ba68e, 54583a3 · Browse files · 6 files·+68 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+68 added−6 removed
- tests:+59 added−1 removed
- other:+9 added−5 removed
Provenance
- Commit
49295a9- Tree
b56306e- Author
zhiyelee <zhiyelee@gmail.com>- Committer
zhiyelee <zhiyelee@gmail.com>- Parent 1
30ba68e- Parent 2
54583a3
6 files changed+68 added−6 removed
added:test/test.options.bool.optional.given.js+21 added
123456789101112131415161718192021/** * Module dependencies. */
var program = require('../') , should = require('should');
//can be loaded from a config filevar config = { pepper: true, cheese: false}
program .version('0.0.1') .option('-p, --pepper [boolean]', 'add pepper', config.pepper || false) .option('-c, --cheese [boolean]', 'remove cheese', config.cheese || false);
program.parse(['node', 'test', '--pepper', 'false', '--cheese', 'true']);program.pepper.should.be.false;program.cheese.should.be.true;added:test/test.options.bool.optional.js+21 added
123456789101112131415161718192021/** * Module dependencies. */
var program = require('../') , should = require('should');
//can be loaded from a config filevar config = { pepper: true, cheese: false}
program .version('0.0.1') .option('-p, --pepper [boolean]', 'add pepper', config.pepper || false) .option('-c, --cheese [boolean]', 'remove cheese', config.cheese || false);
program.parse(['node', 'test']);program.pepper.should.be.true;program.cheese.should.be.false;modified:test/test.options.func.js+3 added-1 removed
5 unmodified lines67891011121213141516171819202122235 unmodified lines .description('sdfdsfsfsdfdsf') .option('-f, --foo', 'add some foo') .option('-b, --bar', 'add some bar') .option('-M, --no-magic', 'disable magic') .option('-c, --camel-case', 'convert to camelCase') .option('-q, --quux <quux>', 'add some quux');
program.parse(['node', 'test', '--foo', '--bar', '--no-magic', '--quux', 'value']);program.parse(['node', 'test', '--foo', '--bar', '--no-magic', '--camel-case', '--quux', 'value']);program.opts.should.be.a.Function;
var opts = program.opts();opts.should.be.an.Object;opts.version.should.equal('0.0.1');opts.foo.should.be.true;opts.bar.should.be.true;opts.magic.should.be.false;opts.camelCase.should.be.true;opts.quux.should.equal('value');added:test/test.options.same-name-arg.js+14 added
1234567891011121314/** * Module dependencies. */
var program = require('../') , should = require('should');
program .version('0.0.1') .option('--string <n>', 'pass a string')
program.parse('node test string --string myString'.split(' '));program.string.should.equal('myString');program.args.should.containEql('string');modified:index.js+7 added-5 removed
286 unmodified lines287 }288 289 fn.apply(self, args);290 };291- this.parent.on(this._name, listener);292- if (this._alias) this.parent.on(this._alias, listener);291+ this.parent.on('action_' + this._name, listener);292+ if (this._alias) this.parent.on('action_' + this._alias, listener);293 return this;294 };295 296 /**91 unmodified lines388 if (null == val) {389 self[name] = option.bool390 ? defaultValue || true391 : false;392+ } else if (option.flags.indexOf('<boolean>') > -1 || option.flags.indexOf('[boolean]') > -1) {393+ self[name] = (val === 'true');394 } else {395 self[name] = val;396 }397 } else if (null !== val) {171 unmodified lines569 var name;570 571 if (args.length) {572 name = args[0];571- if (this.listeners(name).length) {572- this.emit(args.shift(), args, unknown);573+ if (this.listeners('action_' + name).length) {574+ this.emit('action_' + args.shift(), args, unknown);575 } else {576 this.emit('*', args);577 }578 } else {114 unmodified lines693 var result = {}694 , len = this.options.length;695 696 for (var i = 0 ; i < len; i++) {695- var key = this.options[i].name();697+ var key = camelcase(this.options[i].name());698 result[key] = key === 'version' ? this._version : this[key];699 }700 return result;701 };352 unmodified linesmodified:Readme.md+2 added
1 # Commander.js2 3+[](https://gitter.im/tj/commander.js?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)4+5 [](http://travis-ci.org/tj/commander.js)6 [](https://www.npmjs.org/package/commander)7 [](https://www.npmjs.org/package/commander)8 321 unmodified lines