Skip to content

Commit

Permalink
feat: Add DENO_NO_PROMPT variable (denoland#14209)
Browse files Browse the repository at this point in the history
This commit adds support for "DENO_NO_PROMPT" env
variable, that can be used instead of "--no-prompt" flag
to completely disable permission prompts.
  • Loading branch information
nayeemrmn committed Apr 18, 2022
1 parent bf804d3 commit 66fbdd2
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 10 deletions.
11 changes: 9 additions & 2 deletions cli/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
}
Expand Down
5 changes: 3 additions & 2 deletions cli/tests/integration/bench_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
});
Expand Down
20 changes: 20 additions & 0 deletions cli/tests/integration/run_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
4 changes: 2 additions & 2 deletions cli/tests/integration/test_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
});
Expand Down
1 change: 0 additions & 1 deletion cli/tests/testdata/bench/no_prompt_by_default.out
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
1 change: 0 additions & 1 deletion cli/tests/testdata/bench/no_prompt_with_denied_perms.out
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
10 changes: 10 additions & 0 deletions cli/tests/testdata/no_prompt.ts
Original file line number Diff line number Diff line change
@@ -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 change: 0 additions & 1 deletion cli/tests/testdata/test/no_prompt_by_default.out
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
1 change: 0 additions & 1 deletion cli/tests/testdata/test/no_prompt_with_denied_perms.out
Original file line number Diff line number Diff line change
@@ -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)

Expand Down

0 comments on commit 66fbdd2

Please sign in to comment.