commander
Advanced tools
Comparing version 2.5.0 to 2.5.1
18
index.js
@@ -151,3 +151,3 @@ | ||
* @param {String} name | ||
* @param {String} [desc] | ||
* @param {String} [desc] for git-style sub-commands | ||
* @return {Command} the new command | ||
@@ -160,8 +160,13 @@ * @api public | ||
var cmd = new Command(args.shift()); | ||
if (desc) cmd.description(desc); | ||
if (desc) this.executables = true; | ||
if (desc) this._execs[cmd._name] = true; | ||
if (desc) { | ||
cmd.description(desc); | ||
this.executables = true; | ||
this._execs[cmd._name] = true; | ||
} | ||
this.commands.push(cmd); | ||
cmd.parseExpectedArgs(args); | ||
cmd.parent = this; | ||
if (desc) return this; | ||
@@ -212,7 +217,6 @@ return cmd; | ||
if (argDetails.name.indexOf('...') === argDetails.name.length - 3) { | ||
if (argDetails.name.length > 3 && argDetails.name.slice(-3) === '...') { | ||
argDetails.variadic = true; | ||
argDetails.name = argDetails.name.slice(0, -3); | ||
} | ||
if (argDetails.name) { | ||
@@ -272,3 +276,3 @@ self._args.push(argDetails); | ||
args[i] = args.slice(i); | ||
args[i] = args.splice(i); | ||
} | ||
@@ -275,0 +279,0 @@ }); |
{ | ||
"name": "commander" | ||
, "version": "2.5.0" | ||
, "version": "2.5.1" | ||
, "description": "the complete solution for node.js command-line programs" | ||
@@ -5,0 +5,0 @@ , "keywords": ["command", "option", "parser", "prompt"] |
@@ -7,3 +7,4 @@ # Commander.js | ||
The complete solution for [node.js](http://nodejs.org) command-line interfaces, inspired by Ruby's [commander](https://github.com/tj/commander). | ||
The complete solution for [node.js](http://nodejs.org) command-line interfaces, inspired by Ruby's [commander](https://github.com/tj/commander). | ||
API documentation: [http://tj.github.com/commander.js/](http://tj.github.com/commander.js/) | ||
@@ -77,2 +78,19 @@ | ||
## Git-style sub-commands | ||
```js | ||
// file: ./examples/pm | ||
var program = require('..'); | ||
program | ||
.version('0.0.1') | ||
.command('install [name]', 'install one or more packages') | ||
.command('search [query]', 'search with optional query') | ||
.command('list', 'list packages installed') | ||
.parse(process.argv); | ||
``` | ||
When `.command()` is invoked with a description argument, no `.action(callback)` should be called to handle sub-commands, otherwise there will be an error. This tells commander that you're going to use separate executables for sub-commands, much like `git(1)` and other popular tools. | ||
The commander will try to find the executable script in __current directory__ with the name `scriptBasename-subcommand`, like `pm-install`, `pm-search`. | ||
## Automated --help | ||
@@ -157,3 +175,3 @@ | ||
var program = require('../'); | ||
var program = require('commander'); | ||
@@ -182,3 +200,3 @@ program | ||
yielding the following help output: | ||
Yields the following help output when `node script-name.js -h` or `node script-name.js --help` are run: | ||
@@ -214,3 +232,2 @@ ``` | ||
- [API documentation](http://tj.github.com/commander.js/) | ||
- [ascii tables](https://github.com/LearnBoost/cli-table) | ||
@@ -217,0 +234,0 @@ - [progress bars](https://github.com/tj/node-progress) |
29843
849
257