Skip to content

Commit

Permalink
fix: implications fails only displayed once (#954)
Browse files Browse the repository at this point in the history
  • Loading branch information
Morishiri authored and bcoe committed Sep 17, 2017
1 parent 73be236 commit ac8088b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
11 changes: 4 additions & 7 deletions lib/validation.js
Expand Up @@ -249,6 +249,7 @@ module.exports = function validation (yargs, usage, y18n) {
;(implied[key] || []).forEach((value) => {
let num
let key = origKey
const origValue = value

// convert string '1' to number 1
num = Number(key)
Expand Down Expand Up @@ -278,20 +279,16 @@ module.exports = function validation (yargs, usage, y18n) {
value = argv[value]
}
if (key && !value) {
implyFail.push(origKey)
implyFail.push(` ${origKey} -> ${origValue}`)
}
})
})

if (implyFail.length) {
let msg = `${__('Implications failed:')}\n`

implyFail.forEach((key) => {
if (implied[key]) {
implied[key].forEach((value) => {
msg += (` ${key} -> ${value}`)
})
}
implyFail.forEach((value) => {
msg += (value)
})

usage.fail(msg)
Expand Down
8 changes: 5 additions & 3 deletions test/validation.js
Expand Up @@ -38,15 +38,17 @@ describe('validation tests', () => {
.argv
})

it('fails if either implied argument is not set', (done) => {
it('fails if either implied argument is not set and displays only failed', (done) => {
yargs(['-f', '-b'])
.implies('f', ['b', 'c'])
.fail((msg1) => {
yargs(['-f', '-c'])
.implies('f', ['b', 'c'])
.fail((msg2) => {
msg1.should.match(/f -> b f -> c/)
msg2.should.match(/f -> b f -> c/)
msg1.should.match(/f -> c/)
msg1.should.not.match(/f -> b/)
msg2.should.match(/f -> b/)
msg2.should.not.match(/f -> c/)
return done()
})
.argv
Expand Down

0 comments on commit ac8088b

Please sign in to comment.