mirror of
https://github.com/denoland/deno.git
synced 2024-12-21 23:04:45 -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:
parent
bf804d3fff
commit
66fbdd2ed4
9 changed files with 44 additions and 10 deletions
11
cli/flags.rs
11
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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",
|
||||
});
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
|
|
@ -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",
|
||||
});
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
10
cli/tests/testdata/no_prompt.ts
vendored
Normal file
10
cli/tests/testdata/no_prompt.ts
vendored
Normal 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);
|
||||
}
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in a new issue