summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNayeem Rahman <nayeemrmn99@gmail.com>2022-04-18 20:08:30 +0100
committerGitHub <noreply@github.com>2022-04-18 21:08:30 +0200
commit66fbdd2ed4b5ecab8a51278cd76bce7adedb4fc2 (patch)
tree55e38ace63362cb49ac8cf9a5f66594a04770335
parentbf804d3ffff39dab3c7fc8a1a91538ec51276223 (diff)
feat: Add DENO_NO_PROMPT variable (#14209)
This commit adds support for "DENO_NO_PROMPT" env variable, that can be used instead of "--no-prompt" flag to completely disable permission prompts.
-rw-r--r--cli/flags.rs11
-rw-r--r--cli/tests/integration/bench_tests.rs5
-rw-r--r--cli/tests/integration/run_tests.rs20
-rw-r--r--cli/tests/integration/test_tests.rs4
-rw-r--r--cli/tests/testdata/bench/no_prompt_by_default.out1
-rw-r--r--cli/tests/testdata/bench/no_prompt_with_denied_perms.out1
-rw-r--r--cli/tests/testdata/no_prompt.ts10
-rw-r--r--cli/tests/testdata/test/no_prompt_by_default.out1
-rw-r--r--cli/tests/testdata/test/no_prompt_with_denied_perms.out1
9 files changed, 44 insertions, 10 deletions
diff --git a/cli/flags.rs b/cli/flags.rs
index 6d853860a..cdd90fa33 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 7b4fbb0a5..e889a8224 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 0953e7239..b99ab2890 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 bac50f16d..3e2df9113 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 3fe67b720..d47198d85 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 f6aec6226..efe9fa6dc 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 000000000..88dccc458
--- /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 705aca689..61fcea8c8 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 d80fb304c..16a2092c5 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)