Skip to content

Commit

Permalink
fix: take into account aliases when appending arrays from config obje…
Browse files Browse the repository at this point in the history
…ct (#199)
  • Loading branch information
juergba authored and bcoe committed Aug 20, 2019
1 parent 7d42572 commit f8a2d3f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ function parse (args, opts) {
} else {
// setting arguments via CLI takes precedence over
// values within the config file.
if (!hasKey(argv, fullKey.split('.')) || (flags.arrays[fullKey] && configuration['combine-arrays'])) {
if (!hasKey(argv, fullKey.split('.')) || (checkAllAliases(fullKey, flags.arrays) && configuration['combine-arrays'])) {
setArg(fullKey, value)
}
}
Expand Down
15 changes: 15 additions & 0 deletions test/yargs-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,21 @@ describe('yargs-parser', function () {
argv.should.have.property('foo', 'bar')
argv.should.have.property('bar', 'baz')
})

it('should combine array typed options with alias and camel-case', function () {
var argv = parser(['--camEl', 'foo', '--camEl', 'bar', '-a', 'red'], {
array: ['cam-el', 'apple'],
alias: { apple: 'a' },
configObjects: [{ camEl: 'baz' }, { a: 'sweet' }],
configuration: {
'combine-arrays': true,
'camel-case-expansion': true
}
})

argv['cam-el'].should.deep.equal(['foo', 'bar', 'baz'])
argv.apple.should.deep.equal(['red', 'sweet'])
})
})

describe('dot notation', function () {
Expand Down

0 comments on commit f8a2d3f

Please sign in to comment.