Skip to content

Commit c8bf536

Browse files
authored
feat: make combining arrays a configurable option (#111)
1 parent 806ddd6 commit c8bf536

File tree

4 files changed

+15
-3
lines changed

4 files changed

+15
-3
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,14 @@ node example.js --no-foo
212212
{ _: [], "no-foo": true }
213213
```
214214
215+
### combine arrays
216+
217+
* default: `false`
218+
* key: `combine-arrays`
219+
220+
Should arrays be combined when provided by both command line arguments and
221+
a configuration file.
222+
215223
### duplicate arguments array
216224
217225
* default: `true`

index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ function parse (args, opts) {
1919
'negation-prefix': 'no-',
2020
'duplicate-arguments-array': true,
2121
'flatten-duplicate-arrays': true,
22-
'populate--': false
22+
'populate--': false,
23+
'combine-arrays': false
2324
}, opts.configuration)
2425
var defaults = opts.default || {}
2526
var configObjects = opts.configObjects || []
@@ -487,7 +488,7 @@ function parse (args, opts) {
487488
} else {
488489
// setting arguments via CLI takes precedence over
489490
// values within the config file.
490-
if (!hasKey(argv, fullKey.split('.')) || (flags.defaulted[fullKey]) || (flags.arrays[fullKey])) {
491+
if (!hasKey(argv, fullKey.split('.')) || (flags.defaulted[fullKey]) || (flags.arrays[fullKey] && configuration['combine-arrays'])) {
491492
setArg(fullKey, value)
492493
}
493494
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"chai": "^3.5.0",
3030
"coveralls": "^2.11.12",
3131
"mocha": "^3.0.1",
32-
"nyc": "^11.2.1",
32+
"nyc": "^11.4.1",
3333
"standard": "^10.0.2",
3434
"standard-version": "^4.0.0"
3535
},

test/yargs-parser.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,9 @@ describe('yargs-parser', function () {
456456
array: ['foo'],
457457
default: {
458458
settings: jsonPath
459+
},
460+
configuration: {
461+
'combine-arrays': true
459462
}
460463
})
461464

0 commit comments

Comments
 (0)