diff --git a/cli/args/flags.rs b/cli/args/flags.rs index e283abc24e5124..584510a48ae44c 100644 --- a/cli/args/flags.rs +++ b/cli/args/flags.rs @@ -3398,8 +3398,9 @@ fn import_map_arg() -> Arg { } fn env_file_arg() -> Arg { - Arg::new("env") - .long("env") + Arg::new("env-file") + .long("env-file") + .alias("env") .value_name("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.") @@ -4792,7 +4793,7 @@ fn import_map_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::("env"); + flags.env_file = matches.remove_one::("env-file"); } fn reload_arg_parse(flags: &mut Flags, matches: &mut ArgMatches) { @@ -7570,7 +7571,7 @@ mod tests { } #[test] - fn run_env_file_default() { + fn run_env_default() { let r = flags_from_vec(svec!["deno", "run", "--env", "script.ts"]); assert_eq!( r.unwrap(), @@ -7585,6 +7586,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] fn run_no_code_cache() { let r = @@ -7601,7 +7618,7 @@ mod tests { } #[test] - fn run_env_file_defined() { + fn run_env_defined() { let r = flags_from_vec(svec!["deno", "run", "--env=.another_env", "script.ts"]); assert_eq!( @@ -7617,6 +7634,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] fn cache_multiple() { let r = diff --git a/cli/args/mod.rs b/cli/args/mod.rs index fcc1a8d7c39163..68a4b0b68393e5 100644 --- a/cli/args/mod.rs +++ b/cli/args/mod.rs @@ -1886,7 +1886,7 @@ fn load_env_variables_from_env_file(filename: Option<&String>) { 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` 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), _ => log::info!("{} Unknown failure occurred with the specified environment file: {}", colors::yellow("Warning"), env_file_name), } diff --git a/tests/testdata/eval/env_file_missing.out b/tests/testdata/eval/env_file_missing.out index 2ec371438ab6bd..b9e219af37665e 100644 --- a/tests/testdata/eval/env_file_missing.out +++ b/tests/testdata/eval/env_file_missing.out @@ -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 diff --git a/tests/testdata/run/env_file_missing.out b/tests/testdata/run/env_file_missing.out index 6ec9b298fc6ff2..f50c1789ee48e9 100644 --- a/tests/testdata/run/env_file_missing.out +++ b/tests/testdata/run/env_file_missing.out @@ -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