weavejester / environ

Library for managing environment variables in Clojure
924 stars 71 forks source link

Override dev config w/ env vars #83

Closed xiongtx closed 6 years ago

xiongtx commented 6 years ago

Is there a way to override the values in the :dev profile when running tests w/ lein test, such that environment variables take precedence?

E.g. when developing locally, I've

{:profiles {:dev {:env {:foo-bar "foo"}}}}

But when running tests in a different environment as part of the build process, where FOO_BAR=bar, I want the environment variables to take precedence over the:dev profile, such that I get bar instead of foo.

The only way I know of is to set the variable before the test command, like FOO_BAR=bar lein test. But it'd be useful to be able to do that implicitly.

weavejester commented 6 years ago

The environment variables do take precendence. If you just write FOO_BAR=bar in the shell, the environment variable is only available for the current process.

To make it available to subprocesses, you use export, e.g. export FOO_BAR=bar.

To make it available for a particular subprocess, you use env or write it in front of the process command, e.g. FOO_BAR=bar lein run or env FOO_BAR=bar lein run.

xiongtx commented 6 years ago

Ah, I see. I guess I misunderstood "resolved in the following order".

Looking closer, I see #79 was motivated by similar confusion. Perhaps "merged" should be used instead of "resolved". "Resolved" implies that once a value is found, the process of searching for values stops.