Skip to content

Commit

Permalink
document using options per command
Browse files Browse the repository at this point in the history
- document that options can be added to a command
- document that command options are validated when the command is used
- document that options are not validated if command has no action
  • Loading branch information
mojavelinux committed Jan 11, 2018
1 parent f13ee18 commit ac337d1
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions Readme.md
Expand Up @@ -64,6 +64,27 @@ if (program.sauce) console.log(' with sauce');
else console.log(' without sauce');
```

## Command-specific options

You can attach options to a command.

```js
#!/usr/bin/env node

var program = require('commander');

program
.command('rm <dir>')
.option('-r, --recursive', 'Remove recursively')
.action(function (dir, cmd) {
console.log('remove ' + dir + (cmd.recursive ? ' recursively' : ''))
})

program.parse(process.argv)
```

A command's options are validated when the command is used. Any unknown options will be reported as an error. However, if an action-based command does not define an action, then the options are not validated.

## Coercion

```js
Expand Down

0 comments on commit ac337d1

Please sign in to comment.