commander
Advanced tools
Comparing version 0.0.5 to 0.1.0
0.1.0 / 2011-08-24 | ||
================== | ||
* Added support for custom `--help` output | ||
0.0.5 / 2011-08-18 | ||
@@ -3,0 +8,0 @@ ================== |
@@ -308,9 +308,2 @@ /*! | ||
// default options | ||
this.option('-h, --help', 'output usage information'); | ||
this.on('help', function(){ | ||
process.stdout.write(this.helpInformation()); | ||
process.exit(0); | ||
}); | ||
// process argv | ||
@@ -890,2 +883,13 @@ this.args = this.parseOptions(this.normalize(argv)); | ||
return str + Array(len + 1).join(' '); | ||
} | ||
} | ||
/** | ||
* Default -h, --help option. | ||
*/ | ||
exports.option('-h, --help', 'output usage information'); | ||
exports.on('help', function(){ | ||
process.stdout.write(this.helpInformation()); | ||
exports.emit('--help'); | ||
process.exit(0); | ||
}); |
{ | ||
"name": "commander" | ||
, "version": "0.0.5" | ||
, "version": "0.1.0" | ||
, "description": "the complete solution for node.js command-line programs" | ||
@@ -5,0 +5,0 @@ , "keywords": ["command", "option", "parser", "prompt", "stdin"] |
@@ -89,2 +89,67 @@ | ||
## Custom help | ||
You can display arbitrary `-h, --help` information | ||
by listening for "--help". Commander will automatically | ||
exit once you are done so that the remainder of your program | ||
does not execute causing undesired behaviours, for example | ||
in the following executable "stuff" will not output when | ||
`--help` is used. | ||
```js | ||
#!/usr/bin/env node | ||
/** | ||
* Module dependencies. | ||
*/ | ||
var program = require('../'); | ||
function list(val) { | ||
return val.split(',').map(Number); | ||
} | ||
program | ||
.version('0.0.1') | ||
.option('-f, --foo', 'enable some foo') | ||
.option('-b, --bar', 'enable some bar') | ||
.option('-B, --baz', 'enable some baz'); | ||
// must be before .parse() since | ||
// node's emit() is immediate | ||
program.on('--help', function(){ | ||
console.log(' Examples:'); | ||
console.log(''); | ||
console.log(' $ custom-help --help'); | ||
console.log(' $ custom-help -h'); | ||
console.log(''); | ||
}); | ||
program.parse(process.argv); | ||
console.log('stuff'); | ||
``` | ||
yielding the following help output: | ||
``` | ||
Usage: custom-help [options] | ||
Options: | ||
-h, --help output usage information | ||
-v, --version output the version number | ||
-f, --foo enable some foo | ||
-b, --bar enable some bar | ||
-B, --baz enable some baz | ||
Examples: | ||
$ custom-help --help | ||
$ custom-help -h | ||
``` | ||
## .prompt(msg, fn) | ||
@@ -91,0 +156,0 @@ |
34357
26
871
259