From f8a2d3f26a84cc57e210deb1aa27b580e4b06388 Mon Sep 17 00:00:00 2001 From: Juerg B <44573692+juergba@users.noreply.github.com> Date: Tue, 20 Aug 2019 03:07:29 +0200 Subject: [PATCH] fix: take into account aliases when appending arrays from config object (#199) --- index.js | 2 +- test/yargs-parser.js | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 79d433c4..7f00f363 100644 --- a/index.js +++ b/index.js @@ -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) } } diff --git a/test/yargs-parser.js b/test/yargs-parser.js index 65d90e40..e51bb3dc 100644 --- a/test/yargs-parser.js +++ b/test/yargs-parser.js @@ -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 () {