- Change the order in which the environment variables from the .env f…#6
- Change the order in which the environment variables from the .env f…#6
Conversation
…ile are merged with the OS environment variables. Variables from the .env file can override OS environment variables. - Add the possibility within the .env file to refer to variables within the .env file or to replace the placeholder variable with the value from the OS environment variable.
…vironment variables or if the placeholder is empty.
|
Interesting, thanks for the ideas. These are two distinct changes:
In the meantime, if you're ok with putting the overriding reversal behind a flag, we could just merge that first part. |
main.go
Outdated
| } | ||
| return part | ||
| } | ||
| log.Printf(`Replacing the variable failed, env key is empty: "%s"`, part) |
.env.demo
Outdated
| SHELL=invalid | ||
| YOUR_NAME=Felix | ||
| GREETING=Hello ${YOUR_NAME}! | ||
| TEST_HOME_PATH=${HOME} No newline at end of file |
Makefile
Outdated
| demo: | ||
| LOCAL=demo go run . -f .env.demo env | sort | ||
| demo-convert: | ||
| LOCAL=demo2 go run . -f .env.demo env | sort | sed -E 's/(.*)/-e \1/' | tr '\n' ' ' No newline at end of file |
There was a problem hiding this comment.
missing terminal LF : looks like an editor configuration issue ; maybe add a .editorconfig for that ?
| @@ -138,7 +162,9 @@ func main() { | |||
| }() | |||
|
|
|||
| env := envFromReader(rc) | |||
There was a problem hiding this comment.
As mentioned in the general comment, this reverses the overriding logic, so I think it is better to put it behind a CLI flag.
https://www.npmjs.com/package/env-cmd
The Laravel framework uses exactly this format Also Docker uses the same format e.g. in the Docker files etc.
Variables makes sense in several cases
Ok, I haven't thought about default values yet, would be cool of course, so without and then if you use
Sure, I don't have a problem with that, I could just imagine that sometimes it can be really useful to overwrite certain environment variables, e.g. for the development environment. Best, Felix |
Thanks, nice project, can use it well myself right now.
But I have extended your project a bit. Maybe you can use it too. What do you say to my changes?
Change the order how the environment variables from the .env file merged with the OS environment variables.
Variables from the .env file can override OS environment variables.
Add the possibility within the .env file to refer to variables within the .env file or to replace the placeholder variable with the value from the OS environment variable.