diff options
Diffstat (limited to 'runtime')
-rw-r--r-- | runtime/permissions/lib.rs | 25 | ||||
-rw-r--r-- | runtime/permissions/prompter.rs | 8 |
2 files changed, 28 insertions, 5 deletions
diff --git a/runtime/permissions/lib.rs b/runtime/permissions/lib.rs index b0fa9eb10..55a94d909 100644 --- a/runtime/permissions/lib.rs +++ b/runtime/permissions/lib.rs @@ -12,6 +12,7 @@ use deno_core::serde::Deserialize; use deno_core::serde::Deserializer; use deno_core::serde::Serialize; use deno_core::serde_json; +use deno_core::unsync::sync::AtomicFlag; use deno_core::url; use deno_core::url::Url; use deno_core::ModuleSpecifier; @@ -132,14 +133,20 @@ impl PermissionState { } fn error(name: &str, info: impl FnOnce() -> Option<String>) -> AnyError { - custom_error( - "PermissionDenied", + let msg = if is_standalone() { + format!( + "Requires {}, specify the required permissions during compilation using `deno compile --allow-{}`", + Self::fmt_access(name, info), + name + ) + } else { format!( "Requires {}, run again with the --allow-{} flag", Self::fmt_access(name, info), name - ), - ) + ) + }; + custom_error("PermissionDenied", msg) } /// Check the permission state. bool is whether a prompt was issued. @@ -2313,6 +2320,16 @@ pub fn create_child_permissions( Ok(worker_perms) } +static IS_STANDALONE: AtomicFlag = AtomicFlag::lowered(); + +pub fn mark_standalone() { + IS_STANDALONE.raise(); +} + +pub fn is_standalone() -> bool { + IS_STANDALONE.is_raised() +} + #[cfg(test)] mod tests { use super::*; diff --git a/runtime/permissions/prompter.rs b/runtime/permissions/prompter.rs index 050902d59..e48e0af10 100644 --- a/runtime/permissions/prompter.rs +++ b/runtime/permissions/prompter.rs @@ -11,6 +11,8 @@ use std::io::StderrLock; use std::io::StdinLock; use std::io::Write as IoWrite; +use crate::is_standalone; + /// Helper function to make control characters visible so users can see the underlying filename. fn escape_control_characters(s: &str) -> std::borrow::Cow<str> { if !s.contains(|c: char| c.is_ascii_control() || c.is_control()) { @@ -339,7 +341,11 @@ impl PermissionPrompter for TtyPrompter { )) ); writeln!(&mut output, "┠─ {}", colors::italic(&msg)).unwrap(); - let msg = format!("Run again with --allow-{name} to bypass this prompt."); + let msg = if is_standalone() { + format!("Specify the required permissions during compile time using `deno compile --allow-{name}`.") + } else { + format!("Run again with --allow-{name} to bypass this prompt.") + }; writeln!(&mut output, "┠─ {}", colors::italic(&msg)).unwrap(); write!(&mut output, "┗ {}", colors::bold("Allow?")).unwrap(); write!(&mut output, " {opts} > ").unwrap(); |