From 1a472ad06bdc55b1fa0c0f26ca2d24d709f2e0c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Wed, 7 Dec 2022 20:21:18 +0100 Subject: 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: --- cli/tools/repl/mod.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'cli/tools/repl/mod.rs') 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>, - maybe_eval: Option, + repl_flags: ReplFlags, ) -> Result { 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 { -- cgit v1.2.3