commander
Advanced tools
Comparing version 2.11.0 to 2.12.0
35
index.js
@@ -63,2 +63,14 @@ /** | ||
/** | ||
* Return option name, in a camelcase format that can be used | ||
* as a object attribute key. | ||
* | ||
* @return {String} | ||
* @api private | ||
*/ | ||
Option.prototype.attributeName = function() { | ||
return camelcase( this.name() ); | ||
}; | ||
/** | ||
* Check if `arg` matches the short or long flag. | ||
@@ -159,2 +171,6 @@ * | ||
Command.prototype.command = function(name, desc, opts) { | ||
if(typeof desc === 'object' && desc !== null){ | ||
opts = desc; | ||
desc = null; | ||
} | ||
opts = opts || {}; | ||
@@ -170,3 +186,2 @@ var args = name.split(/ +/); | ||
} | ||
cmd._noHelp = !!opts.noHelp; | ||
@@ -365,3 +380,3 @@ this.commands.push(cmd); | ||
, oname = option.name() | ||
, name = camelcase(oname); | ||
, name = option.attributeName(); | ||
@@ -388,3 +403,6 @@ // default as 3rd arg | ||
// preassign only if we have a default | ||
if (undefined !== defaultValue) self[name] = defaultValue; | ||
if (undefined !== defaultValue) { | ||
self[name] = defaultValue; | ||
option.defaultValue = defaultValue; | ||
} | ||
} | ||
@@ -549,3 +567,3 @@ | ||
proc = spawn('node', args, { stdio: 'inherit', customFds: [0, 1, 2] }); | ||
proc = spawn(process.argv[0], args, { stdio: 'inherit', customFds: [0, 1, 2] }); | ||
} else { | ||
@@ -764,3 +782,3 @@ proc = spawn(bin, args, { stdio: 'inherit', customFds: [0, 1, 2] }); | ||
for (var i = 0 ; i < len; i++) { | ||
var key = camelcase(this.options[i].name()); | ||
var key = this.options[i].attributeName(); | ||
result[key] = key === 'version' ? this._version : this[key]; | ||
@@ -887,2 +905,4 @@ } | ||
if (alias === command._name) throw new Error('Command alias can\'t be the same as its name'); | ||
command._alias = alias; | ||
@@ -954,4 +974,5 @@ return this; | ||
return this.options.map(function(option) { | ||
return pad(option.flags, width) + ' ' + option.description; | ||
}).concat([pad('-h, --help', width) + ' ' + 'output usage information']) | ||
return pad(option.flags, width) + ' ' + option.description | ||
+ (option.defaultValue !== undefined ? ' (default: ' + option.defaultValue + ')' : ''); | ||
}).concat([pad('-h, --help', width) + ' ' + 'output usage information']) | ||
.join('\n'); | ||
@@ -958,0 +979,0 @@ }; |
{ | ||
"name": "commander", | ||
"version": "2.11.0", | ||
"version": "2.12.0", | ||
"description": "the complete solution for node.js command-line programs", | ||
@@ -17,8 +17,5 @@ "keywords": [ | ||
}, | ||
"devDependencies": { | ||
"should": "^11.2.1", | ||
"sinon": "^2.3.5" | ||
}, | ||
"scripts": { | ||
"test": "make test" | ||
"test": "make test && npm run test-typings", | ||
"test-typings": "node_modules/typescript/bin/tsc -p tsconfig.json" | ||
}, | ||
@@ -29,3 +26,11 @@ "main": "index", | ||
], | ||
"dependencies": {} | ||
"dependencies": { | ||
"@types/node": "^7.0.48" | ||
}, | ||
"devDependencies": { | ||
"should": "^11.2.1", | ||
"sinon": "^2.3.5", | ||
"typescript": "^2.6.1" | ||
}, | ||
"typings": "typings/index.d.ts" | ||
} |
@@ -47,3 +47,22 @@ # Commander.js | ||
Note that multi-word options starting with `--no` prefix negate the boolean value of the following word. For example, `--no-sauce` sets the value of `program.sauce` to false. | ||
```js | ||
#!/usr/bin/env node | ||
/** | ||
* Module dependencies. | ||
*/ | ||
var program = require('commander'); | ||
program | ||
.option('--no-sauce', 'Remove sauce') | ||
.parse(process.argv); | ||
console.log('you ordered a pizza'); | ||
if (program.sauce) console.log(' with sauce'); | ||
else console.log(' without sauce'); | ||
``` | ||
## Coercion | ||
@@ -289,5 +308,5 @@ | ||
if (!process.argv.slice(2).length) { | ||
program.outputHelp(make_red); | ||
} | ||
if (!process.argv.slice(2).length) { | ||
program.outputHelp(make_red); | ||
} | ||
@@ -294,0 +313,0 @@ function make_red(txt) { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
47331
1000
371
1
3
+ Added@types/node@^7.0.48
+ Added@types/node@7.10.14(transitive)