1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 07:14:47 -05:00

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.
This commit is contained in:
Nayeem Rahman 2022-04-18 20:08:30 +01:00 committed by GitHub
parent bf804d3fff
commit 66fbdd2ed4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 44 additions and 10 deletions

View file

@ -12,6 +12,7 @@ use deno_runtime::permissions::PermissionsOptions;
use log::debug; use log::debug;
use log::Level; use log::Level;
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
use std::env;
use std::net::SocketAddr; use std::net::SocketAddr;
use std::num::NonZeroU32; use std::num::NonZeroU32;
use std::num::NonZeroU8; use std::num::NonZeroU8;
@ -474,7 +475,9 @@ static ENV_VARIABLES_HELP: &str = r#"ENVIRONMENT VARIABLES:
DENO_DIR Set the cache directory DENO_DIR Set the cache directory
DENO_INSTALL_ROOT Set deno install's output directory DENO_INSTALL_ROOT Set deno install's output directory
(defaults to $HOME/.deno/bin) (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. subcommand that doesn't perform type-checking by default.
DENO_WEBGPU_TRACE Directory to use for wgpu traces DENO_WEBGPU_TRACE Directory to use for wgpu traces
HTTP_PROXY Proxy address for HTTP requests 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_ffi = Some(vec![]);
flags.allow_hrtime = true; 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; flags.no_prompt = true;
} }
} }

View file

@ -130,13 +130,14 @@ itest!(filter {
}); });
itest!(no_prompt_by_default { 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, exit_code: 1,
output: "bench/no_prompt_by_default.out", output: "bench/no_prompt_by_default.out",
}); });
itest!(no_prompt_with_denied_perms { 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, exit_code: 1,
output: "bench/no_prompt_with_denied_perms.out", output: "bench/no_prompt_with_denied_perms.out",
}); });

View file

@ -2733,3 +2733,23 @@ itest!(js_root_with_ts_check {
output: "js_root_with_ts_check.js.out", output: "js_root_with_ts_check.js.out",
exit_code: 1, 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());
}

View file

@ -288,13 +288,13 @@ itest!(steps_output_within {
}); });
itest!(no_prompt_by_default { 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, exit_code: 1,
output: "test/no_prompt_by_default.out", output: "test/no_prompt_by_default.out",
}); });
itest!(no_prompt_with_denied_perms { 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, exit_code: 1,
output: "test/no_prompt_with_denied_perms.out", output: "test/no_prompt_with_denied_perms.out",
}); });

View file

@ -1,4 +1,3 @@
Check [WILDCARD]no_prompt_by_default.ts
running 1 bench from [WILDCARD]no_prompt_by_default.ts running 1 bench from [WILDCARD]no_prompt_by_default.ts
bench no prompt ... 1000 iterations FAILED ([WILDCARD]ms) bench no prompt ... 1000 iterations FAILED ([WILDCARD]ms)

View file

@ -1,4 +1,3 @@
Check [WILDCARD]/no_prompt_with_denied_perms.ts
running 1 bench from [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) bench no prompt ... 1000 iterations FAILED ([WILDCARD]ms)

10
cli/tests/testdata/no_prompt.ts vendored Normal file
View file

@ -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);
}

View file

@ -1,4 +1,3 @@
Check [WILDCARD]/no_prompt_by_default.ts
running 1 test from ./test/no_prompt_by_default.ts running 1 test from ./test/no_prompt_by_default.ts
no prompt ... FAILED ([WILDCARD]ms) no prompt ... FAILED ([WILDCARD]ms)

View file

@ -1,4 +1,3 @@
Check [WILDCARD]/no_prompt_with_denied_perms.ts
running 1 test from ./test/no_prompt_with_denied_perms.ts running 1 test from ./test/no_prompt_with_denied_perms.ts
no prompt ... FAILED ([WILDCARD]ms) no prompt ... FAILED ([WILDCARD]ms)