Skip to content
Myr

Document and test description of arguments (#1353)

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

* Add test for command-arguments description in help * Remove blank line after Arguments: to match Options and Commands * Add argument decription to README and example * Put back extra line so no chnage in code

authored by John Gee · committed by GitHub · parent af31e90 · Browse files · 3 files+33 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

3 files+33 added−0 removed

  • tests:+19 added−0 removed
  • other:+14 added−0 removed

3 files+33 added−0 removed

modified:examples/env+9 added
10 unmodified lines
1112program13 .version('0.0.1')14 .arguments('<cmd> [env]')15 .description('test command', {16 cmd: 'command to run',17 env: 'environment to run test in'18 })19 .action(function(cmdValue, envValue) {20 console.log('command:', cmdValue);21 console.log('environment:', envValue || 'no environment given');22 });2324program.parse(process.argv);2526// Try the following:27// node env --help28// node env add29// node env add browser
modified:tests/command.help.test.js+19 added
modified:Readme.md+5 added
366 unmodified lines
367368### Specify the argument syntax369370You use `.arguments` to specify the arguments for the top-level command, and for subcommands they are usually included in the `.command` call. Angled brackets (e.g. `<required>`) indicate required input. Square brackets (e.g. `[optional]`) indicate optional input.371You can optionally describe the arguments in the help by supplying a hash as second parameter to `.description()`.372373Example file: [env](./examples/env)374375```js376program377 .version('0.1.0')378 .arguments('<cmd> [env]')379 .description('test command', {380 cmd: 'command to run',381 env: 'environment to run test in'382 })383 .action(function (cmd, env) {384 console.log('command:', cmd);385 console.log('environment:', env || 'no environment given');386 });
395 unmodified lines