feat(unstable): deno run --env (#20300)

This change adds the `--env=[FILE]` flag to the `run`, `compile`,
`eval`, `install` and `repl` subcommands. Environment variables set in
the CLI overwrite those defined in the `.env` file.
This commit is contained in:
Asher Gomez 2023-11-02 02:21:13 +11:00 committed by GitHub
parent 53248e9bb3
commit f8f4e77632
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 134 additions and 4 deletions

View file

@ -52,6 +52,7 @@ use deno_runtime::deno_tls::rustls_pemfile;
use deno_runtime::deno_tls::webpki_roots;
use deno_runtime::inspector_server::InspectorServer;
use deno_runtime::permissions::PermissionsOptions;
use dotenvy::from_filename;
use once_cell::sync::Lazy;
use once_cell::sync::OnceCell;
use serde::Deserialize;
@ -651,6 +652,12 @@ impl CliOptions {
let maybe_vendor_folder =
resolve_vendor_folder(&initial_cwd, &flags, maybe_config_file.as_ref());
if let Some(env_file_name) = &flags.env_file {
if (from_filename(env_file_name)).is_err() {
bail!("Unable to load '{env_file_name}' environment variable file")
}
}
Ok(Self {
flags,
initial_cwd,