Skip to content

Commit

Permalink
fix: for args that have skipValidation set to true, check if the pa…
Browse files Browse the repository at this point in the history
…rsed arg is `true` (#619)

* For args that have skipValidation set to `true`, check if the parsed arg is `true`

When an arg is defined, it will always exist in the parsed argv. Thus, validation would always be skipped, regardless of whether an arg that has `skipValidation` set to `true` is actually passed on the command line. This commit checks to see if the parsed argv value is actually set to true.

* Added test for `skipValidation` fix
  • Loading branch information
faazshift authored and bcoe committed Sep 30, 2016
1 parent 0be7bf3 commit 658a34c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 14 additions & 0 deletions test/yargs.js
Expand Up @@ -1051,6 +1051,20 @@ describe('yargs dsl tests', function () {
.argv
argv.koala.should.equal(true)
})

it('allows having an option that skips validation but not skipping validation if that option is not used', function () {
var skippedValidation = true
yargs(['--no-skip'])
.demand(5)
.option('skip', {
skipValidation: true
})
.fail(function (msg) {
skippedValidation = false
})
.argv
expect(skippedValidation).to.equal(false)
})
})

describe('.help()', function () {
Expand Down
2 changes: 1 addition & 1 deletion yargs.js
Expand Up @@ -824,7 +824,7 @@ function Yargs (processArgs, cwd, parentRequire) {
// Check if any of the options to skip validation were provided
if (!skipValidation && options.skipValidation.length > 0) {
skipValidation = Object.keys(argv).some(function (key) {
return options.skipValidation.indexOf(key) >= 0
return options.skipValidation.indexOf(key) >= 0 && argv[key] === true
})
}

Expand Down

0 comments on commit 658a34c

Please sign in to comment.