-
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(cli): support multiple env file argument #26527
feat(cli): support multiple env file argument #26527
Conversation
e1ddf39
to
5b01b76
Compare
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.
@bp7968h looks good, maybe you could add another test in tests/integration/run_tests.rs
next to env_file
test that uses two --env
flags and showcases that the variables are properly overriden.
Note to self: https://docs.deno.com/runtime/reference/env_variables/#.env-file needs to be updated when this PR lands.
running 3 tests test run::env_file ... ok test run::env_file_missing ... ok test run::env_file_multiple ... ok test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 1102 filtered out; finished in 0.78s
…ncreased a number to lint as all env_file test would be in the same place
dc372d5
to
a2a512d
Compare
Hey @bp7968h, we're ready to merge this PR, could you please resolve the conflicts? |
tests/integration/run_tests.rs
Outdated
@@ -428,6 +428,11 @@ itest!(env_file_missing { | |||
output: "run/env_file_missing.out", | |||
}); | |||
|
|||
itest!(env_file_multiple { |
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.
Could I actually ask you to rewrite these three env_file_
tests to spec tests? You can see some examples in tests/specs/run/
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.
Sure, will do so thank you for pointing it out.
@@ -3775,12 +3775,14 @@ fn env_file_arg() -> Arg { | |||
.help(cstr!( | |||
"Load environment variables from local file | |||
<p(245)>Only the first environment variable with a given key is used. | |||
Existing process environment variables are not overwritten.</>" | |||
Existing process environment variables are not overwritten, so if variables with the same names already exist in the environment, their values will be preserved. | |||
Where multiple declarations for the same environment variable exist in your .env file, the first one encountered is applied. This is determined by the order of the files you pass as arguments.</>" | |||
)) | |||
.value_hint(ValueHint::FilePath) | |||
.default_missing_value(".env") | |||
.require_equals(true) | |||
.num_args(0..=1) |
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.
should we allow specifying multiple values in a single declaration as well?
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.
Hi @crowlKats , before this PR the behavior was that if multiple declaration of the same variable exists in the .env file, the first one was applied. For example:
VAR="one"
VAR="two"
For the above single env file, VAR='one'
would take effect, and this behavior remains the same while passing multiple env file but according to order of files passed, that is if the above was the last file passed and other preceding file also had VAR in it, then 'VAR='one'' is applied.
Please suggest, if this is something that we are looking or any anything else.
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.
no what i meant multiple files in a single flag call, as in --env-file=.env.one,.env.two
in addition to allowing multiple calls to --env-file
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.
hmm, that is achievable using the delimiter flag in clap I guess. Do you want me to update the code @crowlKats ?
@bp7968h could you please open a PR to |
Hi @bartlomieju, is that the only place where the docs should be updated, but when I google |
Sure, that's a good idea to update that page too. |
Hi @bartlomieju, I have created the PR, can you please review if the writing is ok. |
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, thank you @bp7968h, nice work
Related Issue
Fixes #26425
Overview
This PR adds support for specifying multiple environment files as arguments when using the Deno CLI. Subsequent files override pre-existing variables defined in previous files.
If the same variable is defined in the environment and in the file, the value from the environment takes precedence.
Example Usage