Specify directory containing .env files
Stadly opened this issue · 3 comments
When using cascading env variables, you might end up with a lot of .env
files. It is then common to group the .env
files in a folder. Would it be possible to add a flag for specifying where dotenv
should look for .env
files? I suggest -d <dir>
. For consistency, I think it should also work without -c
, though that is probably the main use case.
# Load vars/.env (-d without -e or -c)
dotenv -d vars <cmd>
# Load vars/.env2 (-d combined with -e)
dotenv -d vars -e .env2 <cmd>
# Load env/.env.local and env/.env (-d combined with -c)
dotenv -d env -c <cmd>
I see how that could be useful. I will accept a PR like this
After looking at the source code, I'm not sure -d
is needed after all. Since -c
cascades all files added with -e
, the behavior provided by -d
can already be achieved with the current functionality:
# Load vars/.env
dotenv -e vars/.env <cmd>
# Load vars/.env2
dotenv -e vars/.env2 <cmd>
# Load env/.env.local and env/.env (the use case I thought wasn't possible without -d)
dotenv -e env/.env -c <cmd>
What do you think?
Yeah, I guess it might be better to keep the cli clean and lean and not add it. I guess if we really want to improve something, we could update the readme.