Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make combining arrays a configurable option #111

Merged
merged 1 commit into from
Dec 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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