-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(unstable): deno run --env
#20300
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good start 👍 can you add some integration tests that check that the file is actually loaded?
How does this change fit in with the dotenv std module? There is obviously overlap, loading from a .env file. Some thoughts:
|
There is some overlap, however with
Probably yes, however
We would certainly keep the
Not sure, and I'm not sure if that matters. We will need to check that. It's not 100% agreed that we'll use
That was also one of the requirements for this feature - no magic discovery, not walking up the file system. In more detail the requirements for this feature are as follows:
|
Thanks @bartlomieju, makes sense. |
Changes made. Still, work to do. Regarding the requirements:
TL;DR |
No, we should return an error if the value of the
That's a bummer :/
That's good to hear 👍
👍
If that's the case we should consider We also floated the idea that env vars defined in the dotenv file wouldn't require |
Couldn't there be secrets there? Like API keys to non-production resources. |
Good point. I guess we can skip that part for now and reevaluate in the future. |
@iuioiua did you have a chance to verify if variable substitution and conflict handling is working in |
Not yet. I should have a chance within the next couple of days. That cool? |
|
I think the more common use case would be if the env variable set in .env was already in the process environment, rather than the use case of duplication in the .env file. I think the behaviour is the same (the process env value is not overwritten), but it might be worth explicitly stating this in the docs. |
@@ -391,6 +391,7 @@ pub struct Flags { | |||
pub ext: Option<String>, | |||
pub ignore: Vec<PathBuf>, | |||
pub import_map_path: Option<String>, | |||
pub env_file: Option<String>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was also one of the requirements for this feature - no magic discovery, not walking up the file system.
Generally a .env
file would be stored right beside a deno.json. If a deno.json exists, maybe we should traverse up and stop at the deno.json directory when someone provides --env
with no path?
I looked into this a bit and started extracting out some of the code from deno_task_shell, which will help us get this feature exactly how we like it and improve future integration. It's not too complicated, but there are some differences between the variable expansion (see https://github.com/motdotla/dotenv-expand/blob/master/tests/.env). Let's push this off to the next release. |
I've updated the command description.
I've updated tests to match those, which are expectedly now failing. Is that what you'd like us to aim towards, @dsherret?
Can you elaborate on how this is done? |
Extracted out some of the parsing functions and repurposed them. I haven't worked on it for a few weeks and it currently doesn't compile.
I think we can just merge this with |
Signed-off-by: Asher Gomez <ashersaupingomez@gmail.com>
cli/args/mod.rs
Outdated
if let Some(env_file_name) = &flags.env_file { | ||
from_filename(env_file_name).unwrap_or_else(|_| { | ||
panic!( | ||
"Unable to load '{}' environment variable file", | ||
env_file_name.as_str() | ||
) | ||
}); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Panicking seems wrong to me. How would we like to handle the error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use bail!
instead which will return an error
Alright, I think this is ready. I've completed up to what I can, for now. I'm unsure how to do the present and missing env file tests for the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks @iuioiua!
Let's land this as unstable then circle back with other fixes and improvements in the coming releases.
This reverts commit 117bfc9.
Nice! Thanks for making the finishing touches. Sorry it took so long 😅 |
This change adds the
--env=[FILE]
flag to therun
,compile
,eval
,install
andrepl
subcommands. Environment variables set in the CLI overwrite those defined in the.env
file.