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

Added config-dot-notation for config files. #190

Closed
wants to merge 2 commits into from
Closed

Added config-dot-notation for config files. #190

wants to merge 2 commits into from

Conversation

f0zi
Copy link

@f0zi f0zi commented Jul 23, 2019

In reply to yargs/yargs#1305.

Copy link
Member

@bcoe bcoe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a few nits, this is looking great.

README.md Outdated
@@ -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`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps:

_Note: as of [email protected], dot-notationhas been split intodot-notationandconfig-dot-notation_

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I was expecting this :)

README.md Outdated
* default: `false`
* key: `config-dot-notation`

Should keys in the config file that contain `.` split up in objects?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

Should keys in the config file that contain . be split into objects.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NP

@@ -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 },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this logic should need to change because we don't have keys of the form "foo.bar"?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I see what you mean, but it fails without it. Ok, I'll have to look into this one more, tomorrow or Friday.

@@ -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: {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to add two tests, demonstrating "foo.bar" with config-dot-notation enabled and disabled.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I was thinking of adding a test but I saw "does not append nested-object keys from config to top-level key" seems to be testing exactly that.

Except, now that I look at it again, the only thing I would change is line 2100 change 'dot-notation': false to 'config-dot-notation': false to make it explicit.

Or would you rather like me to add another test case for this?

Copy link
Member

@bcoe bcoe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'm either misunderstanding your goals, or there's a bug in this implementation.

I thought what we wanted was for keys in config files with .s to not be expanded.

I believe in this current implementation, we just skip merging objects that are served via arguments with objects that are served via config files.

@@ -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']) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic seems wrong to me, which I believe is why you've had to explicitly turn on config-dot-notation to get tests passing.

What I believe we want, when config-dot-notation is false is to still run setConfigObject (which takes care of merging the config file with our arguments.

It's a specific edge-case you want to turn off, which is how someone handles a config file that looks like this:

{
  "foo.com": {
     "hello": "world"
  }
}

@bcoe
Copy link
Member

bcoe commented Sep 6, 2019

just wanted to bump this PR back up, still something you'd like to see over the finish line @f0zi?

@f0zi
Copy link
Author

f0zi commented Sep 13, 2019

I'd love to, but I don't think I have the time for this in the next few weeks or so.

If you don't mind, don't close it, I might come back to it when I find some time.

@bcoe
Copy link
Member

bcoe commented Feb 9, 2020

@f0zi closing for now, but please feel free to come back and dust this off when you have time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants