Thanks for the reply, José. Appreciate it!
> Right, that's because the alias still reads the environment from
the task, since you are using "mix test" as the entry point. You could
do this:
>
> preferred_cli_env: [test: :ci]
I don't think that will work as MIX_ENV is set to "local" by default. E.g., if I run "echo $MIX_ENV" in the shell it will print "local". Since MIX_ENV is persistently set, it takes precedence over the preferred_cli_env setting leaving us no other choice than explicitly setting MIX_ENV before running a task expecting a different environment. And, if I'm not mistaken, the configuration is being loaded before the Mix tasks run, so the "local" configuration file will be loaded (incorrectly) when invoking mix test.
> But my suggestion would be to use a "mix ci" task instead (that matches
your environment). "mix test" will still be around but running it will
fail anyway if the env is missing.
I like this idea! However, I still need to run the tests, and at that point I'll face the same issues I've described above. Right?
I think there's a couple of problems here. Since you can't override the default environment you must set MIX_ENV. If MIX_ENV is persistently set, it will interfere with Mix tasks as it always load the configuration associated with the value of MIX_ENV. Furthermore, since MIX_ENV is set, it will make preferred_cli_env mute as it takes precedence. This leaves us with the following options:
1. Don't persistently set MIX_ENV and always specify it before running a mix task. This is cumbersome and error-prone.
2. Persistently set MIX_ENV to the default environment and then explicitly set it to something else when invoking specific tasks. Less cumbersome but still somewhat error-prone.
3. Leave MIX_ENV unset and explicitly set preferred_cli_env for every single mix task.
I'm still somewhat new to Elixir, so maybe I'm missing some key thing here. If so, feel free to point it out. :)