mirror of
https://github.com/denoland/deno.git
synced 2024-12-24 08:09:08 -05:00
Add emojis to permission prompts (#1684)
This commit is contained in:
parent
aea7884d11
commit
5c50d2819b
9 changed files with 46 additions and 22 deletions
1
BUILD.gn
1
BUILD.gn
|
@ -18,6 +18,7 @@ group("default") {
|
|||
}
|
||||
|
||||
main_extern = [
|
||||
"$rust_build:ansi_term",
|
||||
"$rust_build:atty",
|
||||
"$rust_build:dirs",
|
||||
"$rust_build:flatbuffers",
|
||||
|
|
10
Cargo.lock
generated
10
Cargo.lock
generated
|
@ -1,3 +1,11 @@
|
|||
[[package]]
|
||||
name = "ansi_term"
|
||||
version = "0.11.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "arc-swap"
|
||||
version = "0.3.7"
|
||||
|
@ -184,6 +192,7 @@ dependencies = [
|
|||
name = "deno"
|
||||
version = "0.2.10"
|
||||
dependencies = [
|
||||
"ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"dirs 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"flatbuffers 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -1310,6 +1319,7 @@ dependencies = [
|
|||
]
|
||||
|
||||
[metadata]
|
||||
"checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b"
|
||||
"checksum arc-swap 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "1025aeae2b664ca0ea726a89d574fe8f4e77dd712d443236ad1de00379450cf6"
|
||||
"checksum argon2rs 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "3f67b0b6a86dae6e67ff4ca2b6201396074996379fba2b92ff649126f37cb392"
|
||||
"checksum arrayvec 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)" = "92c7fb76bc8826a8b33b4ee5bb07a247a81e76764ab4d55e8f73e3a4d8808c71"
|
||||
|
|
|
@ -10,6 +10,7 @@ version = "0.2.10"
|
|||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
ansi_term = "0.11.0"
|
||||
atty = "0.2.11"
|
||||
dirs = "1.0.4"
|
||||
flatbuffers = "0.5.0"
|
||||
|
|
2
Docs.md
2
Docs.md
|
@ -200,7 +200,7 @@ the network:
|
|||
|
||||
```
|
||||
> deno https://deno.land/x/examples/echo_server.ts
|
||||
deno requests network access to "listen". Grant? [yN] y
|
||||
⚠️ Deno requests network access to "listen". Grant? [yN] y
|
||||
listening on 0.0.0.0:8080
|
||||
```
|
||||
|
||||
|
|
|
@ -10,6 +10,18 @@ import("rust.gni")
|
|||
|
||||
cargo_home = "//third_party/rust_crates"
|
||||
|
||||
rust_crate("ansi_term") {
|
||||
edition = "2015"
|
||||
source_root = "$cargo_home/registry/src/github.com-1ecc6299db9ec823/ansi_term-0.11.0/src/lib.rs"
|
||||
args = [
|
||||
"--cap-lints",
|
||||
"allow",
|
||||
]
|
||||
if (is_win) {
|
||||
extern = [ ":winapi" ]
|
||||
}
|
||||
}
|
||||
|
||||
rust_crate("arrayvec") {
|
||||
edition = "2015"
|
||||
source_root = "$cargo_home/registry/src/github.com-1ecc6299db9ec823/arrayvec-0.4.10/src/lib.rs"
|
||||
|
|
|
@ -61,6 +61,9 @@ fn print_err_and_exit(err: errors::RustOrJsError) {
|
|||
}
|
||||
|
||||
fn main() {
|
||||
#[cfg(windows)]
|
||||
ansi_term::enable_ansi_support().ok(); // For Windows 10
|
||||
|
||||
log::set_logger(&LOGGER).unwrap();
|
||||
let args = env::args().collect();
|
||||
let (mut flags, mut rest_argv, usage_string) = flags::set_flags(args)
|
||||
|
|
|
@ -3,6 +3,7 @@ use atty;
|
|||
|
||||
use crate::flags::DenoFlags;
|
||||
|
||||
use ansi_term::Style;
|
||||
use crate::errors::permission_denied;
|
||||
use crate::errors::DenoResult;
|
||||
use std::io;
|
||||
|
@ -32,7 +33,7 @@ impl DenoPermissions {
|
|||
return Ok(());
|
||||
};
|
||||
// TODO get location (where access occurred)
|
||||
let r = permission_prompt("Deno requests access to run a subprocess.");
|
||||
let r = permission_prompt("access to run a subprocess");
|
||||
if r.is_ok() {
|
||||
self.allow_run.store(true, Ordering::SeqCst);
|
||||
}
|
||||
|
@ -44,10 +45,7 @@ impl DenoPermissions {
|
|||
return Ok(());
|
||||
};
|
||||
// TODO get location (where access occurred)
|
||||
let r = permission_prompt(&format!(
|
||||
"Deno requests write access to \"{}\".",
|
||||
filename
|
||||
));;
|
||||
let r = permission_prompt(&format!("write access to \"{}\"", filename));;
|
||||
if r.is_ok() {
|
||||
self.allow_write.store(true, Ordering::SeqCst);
|
||||
}
|
||||
|
@ -59,10 +57,8 @@ impl DenoPermissions {
|
|||
return Ok(());
|
||||
};
|
||||
// TODO get location (where access occurred)
|
||||
let r = permission_prompt(&format!(
|
||||
"Deno requests network access to \"{}\".",
|
||||
domain_name
|
||||
));
|
||||
let r =
|
||||
permission_prompt(&format!("network access to \"{}\"", domain_name));
|
||||
if r.is_ok() {
|
||||
self.allow_net.store(true, Ordering::SeqCst);
|
||||
}
|
||||
|
@ -74,8 +70,7 @@ impl DenoPermissions {
|
|||
return Ok(());
|
||||
};
|
||||
// TODO get location (where access occurred)
|
||||
let r =
|
||||
permission_prompt(&"Deno requests access to environment variables.");
|
||||
let r = permission_prompt(&"access to environment variables");
|
||||
if r.is_ok() {
|
||||
self.allow_env.store(true, Ordering::SeqCst);
|
||||
}
|
||||
|
@ -87,8 +82,9 @@ fn permission_prompt(message: &str) -> DenoResult<()> {
|
|||
if !atty::is(atty::Stream::Stdin) || !atty::is(atty::Stream::Stderr) {
|
||||
return Err(permission_denied());
|
||||
};
|
||||
let msg = format!("⚠️ Deno requests {}. Grant? [yN] ", message);
|
||||
// print to stderr so that if deno is > to a file this is still displayed.
|
||||
eprint!("{} Grant? [yN] ", message);
|
||||
eprint!("{}", Style::new().bold().paint(msg));
|
||||
let mut input = String::new();
|
||||
let stdin = io::stdin();
|
||||
let _nread = stdin.read_line(&mut input)?;
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit c8e3a6e37ff575a6f41168235651f5ef684f1989
|
||||
Subproject commit fc22ab76b59256a3cdbfd74776460bc40b6b24fb
|
|
@ -1,4 +1,5 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
||||
import os
|
||||
import pty
|
||||
|
@ -74,7 +75,7 @@ class Prompt(object):
|
|||
code, stdout, stderr = self.run('needsWrite', b'y\n')
|
||||
assert code == 0
|
||||
assert stdout == b''
|
||||
assert b'Deno requests write access' in stderr
|
||||
assert b'⚠️ Deno requests write access' in stderr
|
||||
|
||||
def test_write_arg(self):
|
||||
code, stdout, stderr = self.run('needsWrite', b'', allow_write=True)
|
||||
|
@ -86,13 +87,13 @@ class Prompt(object):
|
|||
code, _stdout, stderr = self.run('needsWrite', b'N\n')
|
||||
assert code == 1
|
||||
assert b'PermissionDenied: permission denied' in stderr
|
||||
assert b'Deno requests write access' in stderr
|
||||
assert b'⚠️ Deno requests write access' in stderr
|
||||
|
||||
def test_env_yes(self):
|
||||
code, stdout, stderr = self.run('needsEnv', b'y\n')
|
||||
assert code == 0
|
||||
assert stdout == b''
|
||||
assert b'Deno requests access to environment' in stderr
|
||||
assert b'⚠️ Deno requests access to environment' in stderr
|
||||
|
||||
def test_env_arg(self):
|
||||
code, stdout, stderr = self.run('needsEnv', b'', allow_env=True)
|
||||
|
@ -104,13 +105,13 @@ class Prompt(object):
|
|||
code, _stdout, stderr = self.run('needsEnv', b'N\n')
|
||||
assert code == 1
|
||||
assert b'PermissionDenied: permission denied' in stderr
|
||||
assert b'Deno requests access to environment' in stderr
|
||||
assert b'⚠️ Deno requests access to environment' in stderr
|
||||
|
||||
def test_net_yes(self):
|
||||
code, stdout, stderr = self.run('needsEnv', b'y\n')
|
||||
assert code == 0
|
||||
assert stdout == b''
|
||||
assert b'Deno requests access to environment' in stderr
|
||||
assert b'⚠️ Deno requests access to environment' in stderr
|
||||
|
||||
def test_net_arg(self):
|
||||
code, stdout, stderr = self.run('needsNet', b'', allow_net=True)
|
||||
|
@ -122,13 +123,13 @@ class Prompt(object):
|
|||
code, _stdout, stderr = self.run('needsNet', b'N\n')
|
||||
assert code == 1
|
||||
assert b'PermissionDenied: permission denied' in stderr
|
||||
assert b'Deno requests network access' in stderr
|
||||
assert b'⚠️ Deno requests network access' in stderr
|
||||
|
||||
def test_run_yes(self):
|
||||
code, stdout, stderr = self.run('needsRun', b'y\n')
|
||||
assert code == 0
|
||||
assert stdout == b'hello'
|
||||
assert b'Deno requests access to run' in stderr
|
||||
assert b'⚠️ Deno requests access to run' in stderr
|
||||
|
||||
def test_run_arg(self):
|
||||
code, stdout, stderr = self.run('needsRun', b'', allow_run=True)
|
||||
|
@ -140,7 +141,7 @@ class Prompt(object):
|
|||
code, _stdout, stderr = self.run('needsRun', b'N\n')
|
||||
assert code == 1
|
||||
assert b'PermissionDenied: permission denied' in stderr
|
||||
assert b'Deno requests access to run' in stderr
|
||||
assert b'⚠️ Deno requests access to run' in stderr
|
||||
|
||||
|
||||
def permission_prompt_test(deno_exe):
|
||||
|
|
Loading…
Reference in a new issue