mirror of
https://github.com/denoland/deno.git
synced 2024-11-28 16:20:57 -05:00
feat(cli): Add --env-file as alternative to --env (#24555)
This commit is contained in:
parent
1d5927aaf2
commit
4c56353594
4 changed files with 46 additions and 8 deletions
|
@ -3410,8 +3410,9 @@ fn import_map_arg() -> Arg {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn env_file_arg() -> Arg {
|
fn env_file_arg() -> Arg {
|
||||||
Arg::new("env")
|
Arg::new("env-file")
|
||||||
.long("env")
|
.long("env-file")
|
||||||
|
.alias("env")
|
||||||
.value_name("FILE")
|
.value_name("FILE")
|
||||||
.help("Load .env file")
|
.help("Load .env file")
|
||||||
.long_help("UNSTABLE: Load environment variables from local file. Only the first environment variable with a given key is used. Existing process environment variables are not overwritten.")
|
.long_help("UNSTABLE: Load environment variables from local file. Only the first environment variable with a given key is used. Existing process environment variables are not overwritten.")
|
||||||
|
@ -4808,7 +4809,7 @@ fn import_map_arg_parse(flags: &mut Flags, matches: &mut ArgMatches) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn env_file_arg_parse(flags: &mut Flags, matches: &mut ArgMatches) {
|
fn env_file_arg_parse(flags: &mut Flags, matches: &mut ArgMatches) {
|
||||||
flags.env_file = matches.remove_one::<String>("env");
|
flags.env_file = matches.remove_one::<String>("env-file");
|
||||||
}
|
}
|
||||||
|
|
||||||
fn reload_arg_parse(flags: &mut Flags, matches: &mut ArgMatches) {
|
fn reload_arg_parse(flags: &mut Flags, matches: &mut ArgMatches) {
|
||||||
|
@ -7606,7 +7607,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn run_env_file_default() {
|
fn run_env_default() {
|
||||||
let r = flags_from_vec(svec!["deno", "run", "--env", "script.ts"]);
|
let r = flags_from_vec(svec!["deno", "run", "--env", "script.ts"]);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
r.unwrap(),
|
r.unwrap(),
|
||||||
|
@ -7621,6 +7622,22 @@ mod tests {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn run_env_file_default() {
|
||||||
|
let r = flags_from_vec(svec!["deno", "run", "--env-file", "script.ts"]);
|
||||||
|
assert_eq!(
|
||||||
|
r.unwrap(),
|
||||||
|
Flags {
|
||||||
|
subcommand: DenoSubcommand::Run(RunFlags::new_default(
|
||||||
|
"script.ts".to_string(),
|
||||||
|
)),
|
||||||
|
env_file: Some(".env".to_owned()),
|
||||||
|
code_cache_enabled: true,
|
||||||
|
..Flags::default()
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn run_no_code_cache() {
|
fn run_no_code_cache() {
|
||||||
let r =
|
let r =
|
||||||
|
@ -7637,7 +7654,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn run_env_file_defined() {
|
fn run_env_defined() {
|
||||||
let r =
|
let r =
|
||||||
flags_from_vec(svec!["deno", "run", "--env=.another_env", "script.ts"]);
|
flags_from_vec(svec!["deno", "run", "--env=.another_env", "script.ts"]);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
@ -7653,6 +7670,27 @@ mod tests {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn run_env_file_defined() {
|
||||||
|
let r = flags_from_vec(svec![
|
||||||
|
"deno",
|
||||||
|
"run",
|
||||||
|
"--env-file=.another_env",
|
||||||
|
"script.ts"
|
||||||
|
]);
|
||||||
|
assert_eq!(
|
||||||
|
r.unwrap(),
|
||||||
|
Flags {
|
||||||
|
subcommand: DenoSubcommand::Run(RunFlags::new_default(
|
||||||
|
"script.ts".to_string(),
|
||||||
|
)),
|
||||||
|
env_file: Some(".another_env".to_owned()),
|
||||||
|
code_cache_enabled: true,
|
||||||
|
..Flags::default()
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn cache_multiple() {
|
fn cache_multiple() {
|
||||||
let r =
|
let r =
|
||||||
|
|
|
@ -1885,7 +1885,7 @@ fn load_env_variables_from_env_file(filename: Option<&String>) {
|
||||||
Err(error) => {
|
Err(error) => {
|
||||||
match 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::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` flag was used, but the environment file specified '{}' was not found.",colors::yellow("Warning"),env_file_name),
|
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),
|
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),
|
_ => log::info!("{} Unknown failure occurred with the specified environment file: {}", colors::yellow("Warning"), env_file_name),
|
||||||
}
|
}
|
||||||
|
|
2
tests/testdata/eval/env_file_missing.out
vendored
2
tests/testdata/eval/env_file_missing.out
vendored
|
@ -1,2 +1,2 @@
|
||||||
Warning The `--env` flag was used, but the environment file specified 'missing' was not found.
|
Warning The `--env-file` flag was used, but the environment file specified 'missing' was not found.
|
||||||
undefined
|
undefined
|
||||||
|
|
2
tests/testdata/run/env_file_missing.out
vendored
2
tests/testdata/run/env_file_missing.out
vendored
|
@ -1,4 +1,4 @@
|
||||||
Warning The `--env` flag was used, but the environment file specified 'missing' was not found.
|
Warning The `--env-file` flag was used, but the environment file specified 'missing' was not found.
|
||||||
undefined
|
undefined
|
||||||
undefined
|
undefined
|
||||||
undefined
|
undefined
|
||||||
|
|
Loading…
Reference in a new issue