Skip to content
Myr

document using options per command

Before adoption: this commit came in with the history the project adopted, so no landing records it.

- 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

authored by Dan Allen · committed by Dan Allen · parent f13ee18 · Browse files · 1 file+21 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+21 added−0 removed

  • other:+21 added−0 removed

1 file+21 added−0 removed

modified:Readme.md+21 added
62 unmodified lines
63if (program.sauce) console.log(' with sauce');64else console.log(' without sauce');65```6667## Command-specific options6869You can attach options to a command.7071```js72#!/usr/bin/env node7374var program = require('commander');7576program77 .command('rm <dir>')78 .option('-r, --recursive', 'Remove recursively')79 .action(function (dir, cmd) {80 console.log('remove ' + dir + (cmd.recursive ? ' recursively' : ''))81 })8283program.parse(process.argv)84```8586A 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.8788## Coercion8990```js91function range(val) {
300 unmodified lines