Skip to content

Commit

Permalink
add callback to allow filtering or post-processing of help text
Browse files Browse the repository at this point in the history
added a callback to allow auto-generated help text to be filtered or
post-processed.  for example, i want to apply colors to the text before
it is displayed in the console.

add callback to allow filtering or post-processing of help text

fix brace alignment in example

make brace alignment in example consistent with other code

add callback to allow filtering or post-processing of help text

added a callback to allow auto-generated help text to be filtered or
post-processed.  for example, i want to apply colors to the text before
it is displayed in the console.

add callback to allow filtering or post-processing of help text

fix brace alignment in example

make brace alignment in example consistent with other code
  • Loading branch information
djulien authored and SomeKittens committed Sep 15, 2015
1 parent 0af40a5 commit 4d421f9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
13 changes: 10 additions & 3 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -268,28 +268,35 @@ Examples:
```

## .outputHelp()
## .outputHelp(cb)

Output help information without exiting.
Optional callback cb allows post-processing of help text before it is displayed.

If you want to display help by default (e.g. if no command was provided), you can use something like:

```js
var program = require('commander');
var colors = require('colors');

program
.version('0.0.1')
.command('getstream [url]', 'get stream URL')
.parse(process.argv);

if (!process.argv.slice(2).length) {
program.outputHelp();
program.outputHelp(make_red);
}

function make_red(txt) {
return colors.red(txt); //display the help text in red on the console
}
```

## .help()
## .help(cb)

Output help information and exit immediately.
Optional callback cb allows post-processing of help text before it is displayed.

## Examples

Expand Down
9 changes: 5 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1017,8 +1017,9 @@ Command.prototype.helpInformation = function() {
* @api public
*/

Command.prototype.outputHelp = function() {
process.stdout.write(this.helpInformation());
Command.prototype.outputHelp = function(cb) {
if (!cb) cb = function(passthru) { return passthru; } //supply benign callback if none specified
process.stdout.write(cb(this.helpInformation()));
this.emit('--help');
};

Expand All @@ -1028,8 +1029,8 @@ Command.prototype.outputHelp = function() {
* @api public
*/

Command.prototype.help = function() {
this.outputHelp();
Command.prototype.help = function(cb) {
this.outputHelp(cb);
process.exit();
};

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "commander",
"version": "2.8.1",
"version": "2.8.2",
"description": "the complete solution for node.js command-line programs",
"keywords": [
"command",
Expand Down

0 comments on commit 4d421f9

Please sign in to comment.