Skip to content

Commit

Permalink
Merge pull request #295 from zhiyelee/git-style-readme
Browse files Browse the repository at this point in the history
add info for git-style subcommand
  • Loading branch information
zhiyelee committed Dec 6, 2014
2 parents 76754b8 + ce5dd0d commit fc543c8
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,23 @@ program.parse(process.argv);
An `Array` is used for the value of a variadic argument. This applies to `program.args` as well as the argument passed
to your action as demonstrated above.

## 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

The help information is auto-generated based on the information commander already knows about your program, so the following `--help` info is for free:
Expand Down

0 comments on commit fc543c8

Please sign in to comment.