Skip to content

Commit

Permalink
fix: populating placeholder arguments broke validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin Coe authored and bcoe committed Mar 10, 2017
1 parent 82c7a4e commit b3eb2fe
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/validation.js
Expand Up @@ -89,7 +89,7 @@ module.exports = function (yargs, usage, y18n) {
var missing = null

Object.keys(demandedOptions).forEach(function (key) {
if (!argv.hasOwnProperty(key)) {
if (!argv.hasOwnProperty(key) || typeof argv[key] === 'undefined') {
missing = missing || {}
missing[key] = demandedOptions[key]
}
Expand Down
18 changes: 18 additions & 0 deletions test/command.js
Expand Up @@ -1299,4 +1299,22 @@ describe('Command', function () {
})
})
})

// addresses: https://github.com/yargs/yargs/issues/819
it('should apply strict argument validation to inner commands', function () {
var called = false
var r = checkOutput(function () {
yargs('foo')
.command('foo', 'foo command', function () {}, function (argv) {
called = true
})
.option('bar', {
describe: 'a foo command',
demand: true
})
.argv
})
called.should.equal(false)
r.errors.should.match(/Missing required argument/)
})
})

0 comments on commit b3eb2fe

Please sign in to comment.