diff --git a/cli/flags.rs b/cli/flags.rs index 6d853860a9..cdd90fa331 100644 --- a/cli/flags.rs +++ b/cli/flags.rs @@ -12,6 +12,7 @@ use deno_runtime::permissions::PermissionsOptions; use log::debug; use log::Level; use once_cell::sync::Lazy; +use std::env; use std::net::SocketAddr; use std::num::NonZeroU32; use std::num::NonZeroU8; @@ -474,7 +475,9 @@ static ENV_VARIABLES_HELP: &str = r#"ENVIRONMENT VARIABLES: DENO_DIR Set the cache directory DENO_INSTALL_ROOT Set deno install's output directory (defaults to $HOME/.deno/bin) - DENO_FUTURE_CHECK Opt-in to the upcoming behavior of the `deno run` + DENO_NO_PROMPT Set to disable permission prompts on access + (alternative to passing --no-prompt on invocation) + DENO_FUTURE_CHECK Opt-in to the upcoming behavior of the `deno run` subcommand that doesn't perform type-checking by default. DENO_WEBGPU_TRACE Directory to use for wgpu traces HTTP_PROXY Proxy address for HTTP requests @@ -2705,7 +2708,11 @@ fn permission_args_parse(flags: &mut Flags, matches: &clap::ArgMatches) { flags.allow_ffi = Some(vec![]); flags.allow_hrtime = true; } - if matches.is_present("no-prompt") { + #[cfg(not(test))] + let has_no_prompt_env = env::var("DENO_NO_PROMPT") == Ok("1".to_string()); + #[cfg(test)] + let has_no_prompt_env = false; + if has_no_prompt_env || matches.is_present("no-prompt") { flags.no_prompt = true; } } diff --git a/cli/tests/integration/bench_tests.rs b/cli/tests/integration/bench_tests.rs index 7b4fbb0a58..e889a82246 100644 --- a/cli/tests/integration/bench_tests.rs +++ b/cli/tests/integration/bench_tests.rs @@ -130,13 +130,14 @@ itest!(filter { }); itest!(no_prompt_by_default { - args: "bench --unstable bench/no_prompt_by_default.ts", + args: "bench --quiet --unstable bench/no_prompt_by_default.ts", exit_code: 1, output: "bench/no_prompt_by_default.out", }); itest!(no_prompt_with_denied_perms { - args: "bench --unstable --allow-read bench/no_prompt_with_denied_perms.ts", + args: + "bench --quiet --unstable --allow-read bench/no_prompt_with_denied_perms.ts", exit_code: 1, output: "bench/no_prompt_with_denied_perms.out", }); diff --git a/cli/tests/integration/run_tests.rs b/cli/tests/integration/run_tests.rs index 0953e72395..b99ab28906 100644 --- a/cli/tests/integration/run_tests.rs +++ b/cli/tests/integration/run_tests.rs @@ -2733,3 +2733,23 @@ itest!(js_root_with_ts_check { output: "js_root_with_ts_check.js.out", exit_code: 1, }); + +itest!(no_prompt_flag { + args: "run --quiet --unstable --no-prompt no_prompt.ts", + output_str: Some(""), +}); + +#[test] +fn deno_no_prompt_environment_variable() { + let output = util::deno_cmd() + .current_dir(util::testdata_path()) + .arg("run") + .arg("--unstable") + .arg("no_prompt.ts") + .env("DENO_NO_PROMPT", "1") + .spawn() + .unwrap() + .wait_with_output() + .unwrap(); + assert!(output.status.success()); +} diff --git a/cli/tests/integration/test_tests.rs b/cli/tests/integration/test_tests.rs index bac50f16dd..3e2df91133 100644 --- a/cli/tests/integration/test_tests.rs +++ b/cli/tests/integration/test_tests.rs @@ -288,13 +288,13 @@ itest!(steps_output_within { }); itest!(no_prompt_by_default { - args: "test test/no_prompt_by_default.ts", + args: "test --quiet test/no_prompt_by_default.ts", exit_code: 1, output: "test/no_prompt_by_default.out", }); itest!(no_prompt_with_denied_perms { - args: "test --allow-read test/no_prompt_with_denied_perms.ts", + args: "test --quiet --allow-read test/no_prompt_with_denied_perms.ts", exit_code: 1, output: "test/no_prompt_with_denied_perms.out", }); diff --git a/cli/tests/testdata/bench/no_prompt_by_default.out b/cli/tests/testdata/bench/no_prompt_by_default.out index 3fe67b720d..d47198d852 100644 --- a/cli/tests/testdata/bench/no_prompt_by_default.out +++ b/cli/tests/testdata/bench/no_prompt_by_default.out @@ -1,4 +1,3 @@ -Check [WILDCARD]no_prompt_by_default.ts running 1 bench from [WILDCARD]no_prompt_by_default.ts bench no prompt ... 1000 iterations FAILED ([WILDCARD]ms) diff --git a/cli/tests/testdata/bench/no_prompt_with_denied_perms.out b/cli/tests/testdata/bench/no_prompt_with_denied_perms.out index f6aec6226c..efe9fa6dc9 100644 --- a/cli/tests/testdata/bench/no_prompt_with_denied_perms.out +++ b/cli/tests/testdata/bench/no_prompt_with_denied_perms.out @@ -1,4 +1,3 @@ -Check [WILDCARD]/no_prompt_with_denied_perms.ts running 1 bench from [WILDCARD]/no_prompt_with_denied_perms.ts bench no prompt ... 1000 iterations FAILED ([WILDCARD]ms) diff --git a/cli/tests/testdata/no_prompt.ts b/cli/tests/testdata/no_prompt.ts new file mode 100644 index 0000000000..88dccc458b --- /dev/null +++ b/cli/tests/testdata/no_prompt.ts @@ -0,0 +1,10 @@ +new Worker("data:,setTimeout(() => Deno.exit(2), 200)", { + type: "module", + deno: { namespace: true }, +}); + +try { + await Deno.run({ cmd: ["ps"] }); +} catch { + Deno.exit(0); +} diff --git a/cli/tests/testdata/test/no_prompt_by_default.out b/cli/tests/testdata/test/no_prompt_by_default.out index 705aca6891..61fcea8c8d 100644 --- a/cli/tests/testdata/test/no_prompt_by_default.out +++ b/cli/tests/testdata/test/no_prompt_by_default.out @@ -1,4 +1,3 @@ -Check [WILDCARD]/no_prompt_by_default.ts running 1 test from ./test/no_prompt_by_default.ts no prompt ... FAILED ([WILDCARD]ms) diff --git a/cli/tests/testdata/test/no_prompt_with_denied_perms.out b/cli/tests/testdata/test/no_prompt_with_denied_perms.out index d80fb304c6..16a2092c54 100644 --- a/cli/tests/testdata/test/no_prompt_with_denied_perms.out +++ b/cli/tests/testdata/test/no_prompt_with_denied_perms.out @@ -1,4 +1,3 @@ -Check [WILDCARD]/no_prompt_with_denied_perms.ts running 1 test from ./test/no_prompt_with_denied_perms.ts no prompt ... FAILED ([WILDCARD]ms)