diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2022-12-07 20:21:18 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-07 20:21:18 +0100 |
commit | 1a472ad06bdc55b1fa0c0f26ca2d24d709f2e0c3 (patch) | |
tree | 7b1c8b615f36916744723e8d60162801eb6127a7 /cli/tools/repl/mod.rs | |
parent | 192f07bb7e2076808cae1eeb6c701cdd3d8d42cd (diff) |
feat(repl): run "deno repl" with no permissions (#16795)
This commit changes "deno repl" command to run with no permissions by
default and accept "--allow-*" flags.
This change is dictated by the fact that currently there is no way to
run REPL with limited permissions. Technically it's a breaking
change in the CLI command, but there's agreement in the team
that it has merit and it's a good solution.
Running just "deno" command still starts the REPL with full permissions
allowed, but now a banner is printed to inform users about that:
Diffstat (limited to 'cli/tools/repl/mod.rs')
-rw-r--r-- | cli/tools/repl/mod.rs | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/cli/tools/repl/mod.rs b/cli/tools/repl/mod.rs index afbd39eff..502105139 100644 --- a/cli/tools/repl/mod.rs +++ b/cli/tools/repl/mod.rs @@ -1,5 +1,7 @@ // Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. +use crate::args::ReplFlags; +use crate::colors; use crate::proc_state::ProcState; use deno_core::error::AnyError; use deno_runtime::permissions::Permissions; @@ -77,8 +79,7 @@ async fn read_eval_file( pub async fn run( ps: &ProcState, worker: MainWorker, - maybe_eval_files: Option<Vec<String>>, - maybe_eval: Option<String>, + repl_flags: ReplFlags, ) -> Result<i32, AnyError> { let mut repl_session = ReplSession::initialize(worker).await?; let mut rustyline_channel = rustyline_channel(); @@ -92,7 +93,7 @@ pub async fn run( let history_file_path = ps.dir.repl_history_file_path(); let editor = ReplEditor::new(helper, history_file_path)?; - if let Some(eval_files) = maybe_eval_files { + if let Some(eval_files) = repl_flags.eval_files { for eval_file in eval_files { match read_eval_file(ps, &eval_file).await { Ok(eval_source) => { @@ -114,7 +115,7 @@ pub async fn run( } } - if let Some(eval) = maybe_eval { + if let Some(eval) = repl_flags.eval { let output = repl_session.evaluate_line_and_get_output(&eval).await?; // only output errors if let EvaluationOutput::Error(error_text) = output { @@ -127,6 +128,13 @@ pub async fn run( if !ps.options.is_quiet() { println!("Deno {}", crate::version::deno()); println!("exit using ctrl+d, ctrl+c, or close()"); + if repl_flags.is_default_command { + println!( + "{}", + colors::yellow("REPL is running with all permissions allowed.") + ); + println!("To specify permissions, run `deno repl` with allow flags.") + } } loop { |