diff --git a/README.md b/README.md index 154ed80cc..c14cb2928 100644 --- a/README.md +++ b/README.md @@ -1382,7 +1382,7 @@ var yargs = require("yargs")(['--help']) Later on, `argv` can be retrieved with `yargs.argv`. -.implies(x, y) +.implies(x, y) -------------- Given the key `x` is set, it is required that the key `y` is set. @@ -1578,6 +1578,7 @@ Valid `opt` keys include: - `coerce`: function, coerce or transform parsed command line values into another value, see [`coerce()`](#coerce) - `config`: boolean, interpret option as a path to a JSON config file, see [`config()`](#config) - `configParser`: function, provide a custom config parsing function, see [`config()`](#config) +- `conflicts`: string or object, require certain keys not to be set, see [`conflicts()`](#conflicts) - `count`: boolean, interpret option as a count of boolean flags, see [`count()`](#count) - `default`: value, set a default value for the option, see [`default()`](#default) - `defaultDescription`: string, use this description for the default value in help content, see [`default()`](#default) @@ -1585,6 +1586,7 @@ Valid `opt` keys include: - `desc`/`describe`/`description`: string, the option description for help content, see [`describe()`](#describe) - `global`: boolean, indicate that this key should not be [reset](#reset) when a command is invoked, see [`global()`](#global) - `group`: string, when displaying usage instructions place the option under an alternative group heading, see [`group()`](#group) +- `implies`: string or object, require certain keys to be set, see [`implies()`](#implies) - `nargs`: number, specify how many arguments should be consumed for the option, see [`nargs()`](#nargs) - `normalize`: boolean, apply `path.normalize()` to the option, see [`normalize()`](#normalize) - `number`: boolean, interpret option as a number, [`number()`](#number) diff --git a/test/validation.js b/test/validation.js index 7b79e2f11..f08080a23 100644 --- a/test/validation.js +++ b/test/validation.js @@ -124,6 +124,18 @@ describe('validation tests', function () { expect(argv.noFoo).to.not.exist expect(argv.foo).to.not.exist }) + + it('allows key to be specified with option shorthand', function (done) { + yargs('--bar') + .option('bar', { + implies: 'foo' + }) + .fail(function (msg) { + msg.should.match(/Implications failed/) + return done() + }) + .argv + }) }) describe('conflicts', function () { @@ -172,6 +184,18 @@ describe('validation tests', function () { }) .argv }) + + it('allows key to be specified with option shorthand', function (done) { + yargs(['-f', '-b']) + .option('f', { + conflicts: 'b' + }) + .fail(function (msg) { + msg.should.equal('Arguments f and b are mutually exclusive') + return done() + }) + .argv + }) }) describe('demand', function () { diff --git a/yargs.js b/yargs.js index 8ee528e62..53a877435 100644 --- a/yargs.js +++ b/yargs.js @@ -535,10 +535,18 @@ function Yargs (processArgs, cwd, parentRequire) { self.config(key, opt.configParser) } + if ('conflicts' in opt) { + self.conflicts(key, opt.conflicts) + } + if ('default' in opt) { self.default(key, opt.default) } + if ('implies' in opt) { + self.implies(key, opt.implies) + } + if ('nargs' in opt) { self.nargs(key, opt.nargs) }