Closed zetlen closed 8 years ago
I support the intended behavior however I'd prefer a different implementation.
I think a design I'd feel more comfortable with would be:
config.set
into a separate methodenv
and argv
convenience methods into the store@pvenkatakrishnan, what do you think?
Thanks @jasisk, that's good advice. I updated the PR to do as you've described; a .toJSON
method on Config objects is no longer necessary.
Is this getting merged sometime soon? I'm having a similar issue but bourne shell uses colon for ENV variable expansion so it seems it would be better to define another character to split ENV variables.
@osukaa I'd like to know too! Also, my tests found this to work fine in Bash; it doesn't seem to invoke the expansion meaning unless you're inside a ${ ... }
, and it doesn't invoke the builtin :
either...
Thought about this a bit tonight. Realized this is already possible. --a.b.c=d
will do what you want.
@jasisk you mean overwriting nested properties in the config.json?
Yup. You can access nested properties from command line arguments by separating them with a period. Note this only applies to command line arguments and not environment variables.
@jasisk what could be a solution for env variables? But thinking of it, could be a bit weird
I swear this didn't work before, @jasisk, but I just tried it again on our local kraken app, and it works now. Witchcraft!
what could be a solution for env variables? But thinking of it, could be a bit weird
something similar to this PR, if we wanted a code change. The other option is something like this:
// config.json
{
"DB_PASSWORD": "default value",
"something": {
"deeply": {
"nested": {
"db": {
"user": "scruffmcgruff",
"password": "config:DB_PASSWORD"
}
}
}
}
}
$ export DB_PASSWORD=60652
$ node thisUsesConfit.js
> // deeply.nested.db.password === "60652"
Thanks!
FYI for others running into an issue like mine.
The original request was for
node app.js --a:b:c=d
But, the solution supports dots instead of colons:
node app.js --a.b.c=d
That makes more sense. I was just struggling for a while wondering why the override wasn't working as I kept trying colon separators.
When i try to override c
with new value for below config structure
node app.js --a.b.c=g
, property e
is getting lost. Is this expected ?
{
"a": {
"b": {
"c": "d"
"e" : "f"
}
}
}
node app.js --a.b.c=g
{
"a": {
"b": {
"c": "g"
"e" : "f"
}
}
}
Confit allows command-line arguments and environment variables to take precedence over config files. However, as observed in https://github.com/krakenjs/confit/issues/42, it does not support setting complex properties. This change uses the existing object traversal code that confit already provides in its JavaScript API to read command-line arguments and environment variables. It enables this:
The resulting overridden config value would be: