From f1f6ea96c0fec9cc8a14d41c6e20353dba6a2af8 Mon Sep 17 00:00:00 2001 From: Benjamin Date: Tue, 19 Dec 2017 21:25:20 -0800 Subject: [PATCH] feat: make combining arrays a configurable option --- README.md | 8 ++++++++ index.js | 5 +++-- package.json | 2 +- test/yargs-parser.js | 3 +++ 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index a368e632..6d6d0d4c 100644 --- a/README.md +++ b/README.md @@ -212,6 +212,14 @@ node example.js --no-foo { _: [], "no-foo": true } ``` +### combine arrays + +* default: `false` +* key: `combine-arrays` + +Should arrays be combined when provided by both command line arguments and +a configuration file. + ### duplicate arguments array * default: `true` diff --git a/index.js b/index.js index 71d1a0c5..1d3e6b9b 100644 --- a/index.js +++ b/index.js @@ -19,7 +19,8 @@ function parse (args, opts) { 'negation-prefix': 'no-', 'duplicate-arguments-array': true, 'flatten-duplicate-arrays': true, - 'populate--': false + 'populate--': false, + 'combine-arrays': false }, opts.configuration) var defaults = opts.default || {} var configObjects = opts.configObjects || [] @@ -487,7 +488,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]) || (flags.arrays[fullKey])) { + if (!hasKey(argv, fullKey.split('.')) || (flags.defaulted[fullKey]) || (flags.arrays[fullKey] && configuration['combine-arrays'])) { setArg(fullKey, value) } } diff --git a/package.json b/package.json index 9717e9e0..8d45574e 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "chai": "^3.5.0", "coveralls": "^2.11.12", "mocha": "^3.0.1", - "nyc": "^11.2.1", + "nyc": "^11.4.1", "standard": "^10.0.2", "standard-version": "^4.0.0" }, diff --git a/test/yargs-parser.js b/test/yargs-parser.js index cf5f0ba6..24825f9e 100644 --- a/test/yargs-parser.js +++ b/test/yargs-parser.js @@ -456,6 +456,9 @@ describe('yargs-parser', function () { array: ['foo'], default: { settings: jsonPath + }, + configuration: { + 'combine-arrays': true } })