Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ function parse (args, opts) {
})
})

checkConfiguration()

var argv = { _: [] }
var notFlags = []

Expand Down Expand Up @@ -874,6 +876,20 @@ function parse (args, opts) {
return num === undefined
}

// check user configuration settings for inconsistencies
function checkConfiguration () {
// count keys should not be set as array/narg
Object.keys(flags.counts).find(key => {
if (checkAllAliases(key, flags.arrays)) {
error = Error(__('Invalid configuration: %s, opts.count excludes opts.array.', key))
return true
} else if (checkAllAliases(key, flags.nargs)) {
error = Error(__('Invalid configuration: %s, opts.count excludes opts.narg.', key))
return true
}
})
}

return {
argv: argv,
error: error,
Expand Down
18 changes: 18 additions & 0 deletions test/yargs-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -1487,6 +1487,24 @@ describe('yargs-parser', function () {
], { count: 'v' })
parsed.v.should.equal(8)
})

it('should add an error if counter is also set as array', function () {
var argv = parser.detailed(['--counter', '--counter', '--counter'], {
count: ['counter'],
array: ['counter']
})

argv.error.message.should.equal('Invalid configuration: counter, opts.count excludes opts.array.')
})

it('should add an error if counter is also set as narg', function () {
var argv = parser.detailed(['--counter', 'foo', 'bar'], {
count: ['counter'],
narg: { 'counter': 2 }
})

argv.error.message.should.equal('Invalid configuration: counter, opts.count excludes opts.narg.')
})
})

describe('array', function () {
Expand Down