From 1b4783d6442ae6353e300aad30600f421ac59e82 Mon Sep 17 00:00:00 2001 From: Fozi Date: Tue, 23 Jul 2019 11:51:51 -0400 Subject: [PATCH 1/2] Added `config-dot-notation` for config files. Defaut is false --- README.md | 27 +++++++++++++++++++++++++++ index.js | 3 ++- test/yargs-parser.js | 2 ++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index dde9f84d..b8af38ac 100644 --- a/README.md +++ b/README.md @@ -177,6 +177,33 @@ node example.js --foo.bar { _: [], "foo.bar": true } ``` +_Note:_ This setting does not apply to config files (any more). See `config-dot-notation`. + +### config-dot-notation + +* default: `false` +* key: `config-dot-notation` + +Should keys in the config file that contain `.` split up in objects? + +example config.json: +```json +{ + "foo.bar": true +} +``` +_if enabled:_ +```sh +node example.js --config config.json +{ _: [], foo: { bar: true } } +``` + +_if disabled:_ +```sh +node example.js --config config.json +{ _: [], "foo.bar": true } +``` + ### parse numbers * default: `true` diff --git a/index.js b/index.js index 11eac1e5..35191234 100644 --- a/index.js +++ b/index.js @@ -16,6 +16,7 @@ function parse (args, opts) { 'short-option-groups': true, 'camel-case-expansion': true, 'dot-notation': true, + 'config-dot-notation': false, 'parse-numbers': true, 'boolean-negation': true, 'negation-prefix': 'no-', @@ -545,7 +546,7 @@ function parse (args, opts) { // if the value is an inner object and we have dot-notation // enabled, treat inner objects in config the same as // heavily nested dot notations (foo.bar.apple). - if (typeof value === 'object' && value !== null && !Array.isArray(value) && configuration['dot-notation']) { + if (typeof value === 'object' && value !== null && !Array.isArray(value) && configuration['config-dot-notation']) { // if the value is an object but not an array, check nested object setConfigObject(value, fullKey) } else { diff --git a/test/yargs-parser.js b/test/yargs-parser.js index 773cfe32..b3d7f35b 100644 --- a/test/yargs-parser.js +++ b/test/yargs-parser.js @@ -567,6 +567,7 @@ describe('yargs-parser', function () { it('should load nested options from config file', function () { var jsonPath = path.resolve(__dirname, './fixtures/nested_config.json') var argv = parser(['--settings', jsonPath, '--nested.foo', 'bar'], { + configuration: { 'config-dot-notation': true }, config: ['settings'] }) @@ -718,6 +719,7 @@ describe('yargs-parser', function () { it('should load nested options from config object', function () { var argv = parser(['--nested.foo', 'bar'], { + configuration: { 'config-dot-notation': true }, configObjects: [{ a: 'a', nested: { From 94c8b6e5788a8492a5cf48b8a6cc187ad8dd4995 Mon Sep 17 00:00:00 2001 From: Fozi Date: Tue, 23 Jul 2019 16:21:31 -0400 Subject: [PATCH 2/2] Readme fixes for config-dot-notation --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b8af38ac..88e2ea7f 100644 --- a/README.md +++ b/README.md @@ -177,14 +177,14 @@ node example.js --foo.bar { _: [], "foo.bar": true } ``` -_Note:_ This setting does not apply to config files (any more). See `config-dot-notation`. +_Note: as of yargs-parser@14.0.0, `dot-notation` has been split into `dot-notation` and `config-dot-notation`_ ### config-dot-notation * default: `false` * key: `config-dot-notation` -Should keys in the config file that contain `.` split up in objects? +Should keys in the config file that contain `.` split into objects? example config.json: ```json