Closed chicoxyzzy closed 3 months ago
I think that it would be super useful to add test coverage for the feature
If I'm understanding correctly, the priority order will be:
- command line
- local env vars
- .env file
Is that right?
Yes, that's correct
I would prefer to either make the option local to the commands it applies to, or always load the file if it's a global option. I like the "always available" if possible, it keeps the mental model simple, but also fine if we pick the other approach as a first step.
The option is always global now
I've just made last changes and tested. It's ready for merge now
This PR adds a
--env-file
option support similar to recently introduced Node.js's--env-file
. Later, when we can add this file todispatch init
under some flags to autogenerate this file and avoid explicit export of environment variables for local development. It's also could be handy for adding rules likemake run-local
which run project against local development environment and other situation.⚠️ Variables from the file do not override the ones passed with command line (default
github.com/joho/godotenv
behavior). I think this correct behavior, but it worth disacussing ⚠️I've realized to only override env variables onThe option is global and it always loads a file when providedPreRunE
Cobra hook to avoid FS operations on dispatch commands other thanrun
andlogin
to make them work faster, but I can change that to always load config as @achille-roussel proposed. The--env-file
is a global option at the moment. We may want to make it non-global or leave it global and always load config. cc @achille-roussel