Skip to content

Commit

Permalink
feat: make combining arrays a configurable option (#111)
Browse files Browse the repository at this point in the history
  • Loading branch information
bcoe authored Dec 20, 2017
1 parent 806ddd6 commit c8bf536
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
5 changes: 3 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 || []
Expand Down Expand Up @@ -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)
}
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
3 changes: 3 additions & 0 deletions test/yargs-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,9 @@ describe('yargs-parser', function () {
array: ['foo'],
default: {
settings: jsonPath
},
configuration: {
'combine-arrays': true
}
})

Expand Down

0 comments on commit c8bf536

Please sign in to comment.