diff --git a/Readme.md b/Readme.md index 636c6dd58..939b8fd7f 100644 --- a/Readme.md +++ b/Readme.md @@ -132,6 +132,31 @@ 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. +## Specify the argument syntax + +```js +#!/usr/bin/env node + +var program = require('../'); + +program + .version('0.0.1') + .arguments(' [env]') + .action(function (cmd, env) { + cmdValue = cmd; + envValue = env; + }); + +program.parse(process.argv); + +if (typeof cmdValue === 'undefined') { + console.error('no command given!'); + process.exit(1); +} +console.log('command:', cmdValue); +console.log('environment:', envValue || "no environment given"); +``` + ## Git-style sub-commands ```js diff --git a/examples/env b/examples/env new file mode 100755 index 000000000..6879cffe9 --- /dev/null +++ b/examples/env @@ -0,0 +1,20 @@ +#!/usr/bin/env node + +var program = require('../'); + +program + .version('0.0.1') + .arguments(' [env]') + .action(function (cmd, env) { + cmdValue = cmd; + envValue = env; + }); + +program.parse(process.argv); + +if (typeof cmdValue === 'undefined') { + console.error('no command given!'); + process.exit(1); +} +console.log('command:', cmdValue); +console.log('environment:', envValue || "no environment given"); diff --git a/test/test.arguments.js b/test/test.arguments.js index cdf6b92b7..b4dfa6df6 100644 --- a/test/test.arguments.js +++ b/test/test.arguments.js @@ -1,5 +1,5 @@ /** - * Module dependencies. + * Top-level command syntax. */ var program = require('../') @@ -17,7 +17,7 @@ program }) .option('-C, --chdir ', 'change the working directory') .option('-c, --config ', 'set config path. defaults to ./deploy.conf') - .option('-T, --no-tests', 'ignore test hook') + .option('-T, --no-tests', 'ignore test hook'); program.parse(['node', 'test', '--config', 'conf']); program.config.should.equal("conf");