Skip to content

Commit

Permalink
feat: merge array from arguments with array from config (yargs#83)
Browse files Browse the repository at this point in the history
  • Loading branch information
markbirbeck authored and bcoe committed Dec 20, 2017
1 parent 3087e1d commit 806ddd6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ function parse (args, opts) {
} else {
// setting arguments via CLI takes precedence over
// values within the config file.
if (!hasKey(argv, fullKey.split('.')) || (flags.defaulted[fullKey])) {
if (!hasKey(argv, fullKey.split('.')) || (flags.defaulted[fullKey]) || (flags.arrays[fullKey])) {
setArg(fullKey, value)
}
}
Expand Down
12 changes: 12 additions & 0 deletions test/yargs-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,18 @@ describe('yargs-parser', function () {
argv.should.have.property('foo').and.deep.equal('baz')
})

it('should combine values from config file and argv, if argv value is an array', function () {
var argv = parser(['--foo', 'bar'], {
config: ['settings'],
array: ['foo'],
default: {
settings: jsonPath
}
})

argv.should.have.property('foo').and.deep.equal(['bar', 'baz'])
})

it('should use value from config file, if argv key is a boolean', function () {
var argv = parser([], {
config: ['settings'],
Expand Down

0 comments on commit 806ddd6

Please sign in to comment.