Skip to content
Myr

Merge branch 'fix---no-logic' of https://github.com/usmonster/commander.js into usmonster-fix---no-logic

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

authored by John Gee · committed by John Gee · parents c13988c, 26594fb · Browse files · 6 files+60 added−19 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+60 added−19 removed

  • tests:+41 added−2 removed
  • other:+19 added−17 removed

6 files+60 added−19 removed

modified:examples/pizza+2 added-4 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 of cheese', 'marble')16 .option('-C, --no-cheese', 'You do not want any cheese')17 .parse(process.argv);1819console.log('you ordered a pizza with:');20if (program.peppers) console.log(' - peppers');21if (program.pineapple) console.log(' - pineapple');22if (program.bbq) console.log(' - bbq');2324var cheese = true === program.cheese25 ? 'marble'26 : program.cheese || 'no';24var cheese = !program.cheese ? 'no' : program.cheese;2526console.log(' - %s cheese', cheese);27console.log(program.args);
modified:test/test.options.bool.no.js+18 added-2 removed
added:test/test.options.defaults.no.js+23 added
modified:index.js+14 added-10 removed
58 unmodified lines
59 * @api private60 */6162Option.prototype.name = function() {63 return this.long64 .replace('--', '')65 .replace('no-', '');63 return this.long.replace(/^--/, '');64};6566/**67 * Return option name, in a camelcase format that can be used
3 unmodified lines
71 * @api private72 */7374Option.prototype.attributeName = function() {77 return camelcase(this.name());75 return camelcase(this.name().replace(/^no-/, ''));76};7778/**79 * Check if `arg` matches the short or long flag.
261 unmodified lines
341 * "-p --pepper"342 *343 * Examples:344 *347 * // simple boolean defaulting to false345 * // simple boolean defaulting to undefined346 * program.option('-p, --pepper', 'add pepper');347 *348 * program.pepper349 * // => undefined350 *351 * --pepper352 * program.pepper352 * // => Boolean353 * // => true354 *354 * // simple boolean defaulting to true355 * // simple boolean defaulting to true (unless non-negated option is also defined)356 * program.option('-C, --no-cheese', 'remove cheese');357 *358 * program.cheese359 * // => true
43 unmodified lines
403 }404405 // preassign default value only for --no-*, [optional], or <required>406 if (!option.bool || option.optional || option.required) {406 // when --no-* we make sure default is true407 if (!option.bool) defaultValue = true;407 // when --no-foo we make sure default is true, unless a --foo option is already defined408 if (!option.bool) {409 var opts = self.opts();410 defaultValue = Object.prototype.hasOwnProperty.call(opts, name) ? opts[name] : true;411 }412 // preassign only if we have a default413 if (defaultValue !== undefined) {414 self[name] = defaultValue;415 option.defaultValue = defaultValue;
22 unmodified lines
438 self[name] = val;439 }440 } else if (val !== null) {441 // reassign438 self[name] = val;442 self[name] = option.bool ? val : false;443 }444 });445446 return this;
849 unmodified lines
modified:package-lock.json+1 added-1 removed
2274 unmodified lines
2275 },2276 "dependencies": {2277 "minimist": {2278 "version": "1.2.0",2279 "resolved": "http://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz",2279 "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz",2280 "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=",2281 "dev": true2282 }2283 }
207 unmodified lines
modified:Readme.md+2 added-2 removed
340 unmodified lines
341342An application for pizzas ordering343344Options:345 -h, --help output usage information345 -V, --version output the version number346 -p, --peppers Add peppers347 -P, --pineapple Add pineapple348 -b, --bbq Add bbq sauce350 -c, --cheese <type> Add the specified type of cheese [marble]349 -c, --cheese <type> Add the specified type of cheese (default: "marble")350 -C, --no-cheese You do not want any cheese351 -h, --help output usage information352```353354## Custom help355
176 unmodified lines