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

Hierarchical argv overrides clobber entire objects #44

Closed
mhart opened this issue Jun 13, 2012 · 2 comments
Closed

Hierarchical argv overrides clobber entire objects #44

mhart opened this issue Jun 13, 2012 · 2 comments

Comments

@mhart
Copy link
Contributor

mhart commented Jun 13, 2012

Here's a simple test case to illustrate what I mean.

test.json:

{
  "database": {
    "host": "localhost",
    "port": 3000
  }
}

test.js:

nconf = require('nconf')

nconf.argv().file({file: 'test.json'})

console.log(nconf.get('database'))

Then run using:

$ node test
{ host: 'localhost', port: 3000 }
$ node test --database:port 8080
{ port: 8080 }

As you can see, the entire database config object is getting clobbered when just one property is overridden. I would have expected just the single property to change/merge.

Is there another way to achieve this?

@mhart
Copy link
Contributor Author

mhart commented Jun 13, 2012

Indeed, this seems to be inconsistent with the following:

nconf = require('nconf')

nconf.argv().file({file: 'test.json'})

console.log(nconf.get('database:host'))
console.log(nconf.get('database:port'))

Yields:

$ node test
localhost
3000
$ node test --database:port 8080
localhost
8080

Which does not seem to match with the clobbering behaviour above (although it does match what I expected).

Note: I want to pass the config objects (ie, database) around, as opposed to nconf itself, so I'd prefer not to have to use the colon syntax everywhere

@jfhbrook
Copy link
Contributor

I agree that doesn't seem right. It's probably short-circuiting on objects instead of continuing down the hierarchy, which makes sense given that this is a special case.

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 a pull request may close this issue.

3 participants