diff options
author | HasanAlrimawi <141642411+HasanAlrimawi@users.noreply.github.com> | 2024-07-10 00:33:41 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-09 21:33:41 +0000 |
commit | fb6348500ffc827b3aaca3e8299e1a3964be43c1 (patch) | |
tree | d73be641e8cfe41512ee275070ee39ca2efe3be6 /cli/mainrt.rs | |
parent | 52946878b26e37849d6688236116e66c14007386 (diff) |
feat(compile): support --env (#24166)
Supported the use of --env flag with the compile subcommand, so that the
generated executable/binary file can access the passed env file.
Diffstat (limited to 'cli/mainrt.rs')
-rw-r--r-- | cli/mainrt.rs | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/cli/mainrt.rs b/cli/mainrt.rs index 6a363c04b..d4f0f558e 100644 --- a/cli/mainrt.rs +++ b/cli/mainrt.rs @@ -31,6 +31,7 @@ pub use deno_runtime::UNSTABLE_GRANULAR_FLAGS; use deno_terminal::colors; use std::borrow::Cow; +use std::collections::HashMap; use std::env; use std::env::current_exe; @@ -70,6 +71,14 @@ fn unwrap_or_exit<T>(result: Result<T, AnyError>) -> T { } } +fn load_env_vars(env_vars: &HashMap<String, String>) { + env_vars.iter().for_each(|env_var| { + if env::var(env_var.0).is_err() { + std::env::set_var(env_var.0, env_var.1); + } + }) +} + fn main() { let args: Vec<_> = env::args_os().collect(); let current_exe_path = current_exe().unwrap(); @@ -79,6 +88,8 @@ fn main() { match standalone { Ok(Some(future)) => { let (metadata, eszip) = future.await?; + util::logger::init(metadata.log_level); + load_env_vars(&metadata.env_vars_from_env_file); let exit_code = standalone::run(eszip, metadata).await?; std::process::exit(exit_code); } |