dispatchrun / dispatch

Entrypoint of the Dispatch ecosystem.
11 stars 1 forks source link

Add dotenv support to `dispatch run` and `dispatch login` commands #57

Closed chicoxyzzy closed 3 months ago

chicoxyzzy commented 3 months ago

This PR adds a --env-file option support similar to recently introduced Node.js's --env-file. Later, when we can add this file to dispatch 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 like make 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 on PreRunE Cobra hook to avoid FS operations on dispatch commands other than run and login 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 The option is global and it always loads a file when provided

chicoxyzzy commented 3 months ago

I think that it would be super useful to add test coverage for the feature

chicoxyzzy commented 3 months ago

If I'm understanding correctly, the priority order will be:

  • command line
  • local env vars
  • .env file

Is that right?

Yes, that's correct

chicoxyzzy commented 3 months ago

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

chicoxyzzy commented 3 months ago

I've just made last changes and tested. It's ready for merge now