summaryrefslogtreecommitdiff
path: root/cli/args/mod.rs
diff options
context:
space:
mode:
authorBhuwan Pandit <bhuwanpandit109@gmail.com>2024-11-17 22:49:35 +0000
committerGitHub <noreply@github.com>2024-11-17 22:49:35 +0000
commitcff6e280c77afb0bc42a10348eeef5360db8f361 (patch)
treea6920ecc1358b23661145b3c03607787a04ae9c6 /cli/args/mod.rs
parent73411bb98a677727799122ebc397d825bf95b812 (diff)
feat(cli): support multiple env file argument (#26527)
Closes #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 ```bash deno run --allow-env --env-file --env-file=".env.one" --env-file=".env.two" script.ts ``` --------- Co-authored-by: Bartek IwaƄczuk <biwanczuk@gmail.com>
Diffstat (limited to 'cli/args/mod.rs')
-rw-r--r--cli/args/mod.rs17
1 files changed, 10 insertions, 7 deletions
diff --git a/cli/args/mod.rs b/cli/args/mod.rs
index 318a6ca76..ec75d7a10 100644
--- a/cli/args/mod.rs
+++ b/cli/args/mod.rs
@@ -1128,7 +1128,7 @@ impl CliOptions {
self.flags.otel_config()
}
- pub fn env_file_name(&self) -> Option<&String> {
+ pub fn env_file_name(&self) -> Option<&Vec<String>> {
self.flags.env_file.as_ref()
}
@@ -1935,19 +1935,22 @@ pub fn config_to_deno_graph_workspace_member(
})
}
-fn load_env_variables_from_env_file(filename: Option<&String>) {
- let Some(env_file_name) = filename else {
+fn load_env_variables_from_env_file(filename: Option<&Vec<String>>) {
+ let Some(env_file_names) = filename else {
return;
};
- match from_filename(env_file_name) {
- Ok(_) => (),
- Err(error) => {
- match error {
+
+ for env_file_name in env_file_names.iter().rev() {
+ match from_filename(env_file_name) {
+ Ok(_) => (),
+ Err(error) => {
+ match error {
dotenvy::Error::LineParse(line, index)=> log::info!("{} Parsing failed within the specified environment file: {} at index: {} of the value: {}",colors::yellow("Warning"), env_file_name, index, line),
dotenvy::Error::Io(_)=> log::info!("{} The `--env-file` flag was used, but the environment file specified '{}' was not found.",colors::yellow("Warning"),env_file_name),
dotenvy::Error::EnvVar(_)=> log::info!("{} One or more of the environment variables isn't present or not unicode within the specified environment file: {}",colors::yellow("Warning"),env_file_name),
_ => log::info!("{} Unknown failure occurred with the specified environment file: {}", colors::yellow("Warning"), env_file_name),
}
+ }
}
}
}