diff options
author | Bhuwan Pandit <bhuwanpandit109@gmail.com> | 2024-11-17 22:49:35 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-17 22:49:35 +0000 |
commit | cff6e280c77afb0bc42a10348eeef5360db8f361 (patch) | |
tree | a6920ecc1358b23661145b3c03607787a04ae9c6 /cli/standalone | |
parent | 73411bb98a677727799122ebc397d825bf95b812 (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/standalone')
-rw-r--r-- | cli/standalone/binary.rs | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/cli/standalone/binary.rs b/cli/standalone/binary.rs index ebcbf3ee6..3efd8ee14 100644 --- a/cli/standalone/binary.rs +++ b/cli/standalone/binary.rs @@ -659,9 +659,15 @@ impl<'a> DenoCompileBinaryWriter<'a> { remote_modules_store.add_redirects(&graph.redirects); let env_vars_from_env_file = match cli_options.env_file_name() { - Some(env_filename) => { - log::info!("{} Environment variables from the file \"{}\" were embedded in the generated executable file", crate::colors::yellow("Warning"), env_filename); - get_file_env_vars(env_filename.to_string())? + Some(env_filenames) => { + let mut aggregated_env_vars = IndexMap::new(); + for env_filename in env_filenames.iter().rev() { + log::info!("{} Environment variables from the file \"{}\" were embedded in the generated executable file", crate::colors::yellow("Warning"), env_filename); + + let env_vars = get_file_env_vars(env_filename.to_string())?; + aggregated_env_vars.extend(env_vars); + } + aggregated_env_vars } None => Default::default(), }; |