summaryrefslogtreecommitdiff
path: root/cli/flags.rs
diff options
context:
space:
mode:
Diffstat (limited to 'cli/flags.rs')
-rw-r--r--cli/flags.rs44
1 files changed, 39 insertions, 5 deletions
diff --git a/cli/flags.rs b/cli/flags.rs
index f42dd771c..2371445c3 100644
--- a/cli/flags.rs
+++ b/cli/flags.rs
@@ -91,7 +91,9 @@ pub enum DenoSubcommand {
rules: bool,
json: bool,
},
- Repl,
+ Repl {
+ eval: Option<String>,
+ },
Run {
script: String,
},
@@ -119,7 +121,7 @@ pub enum DenoSubcommand {
impl Default for DenoSubcommand {
fn default() -> DenoSubcommand {
- DenoSubcommand::Repl
+ DenoSubcommand::Repl { eval: None }
}
}
@@ -955,6 +957,13 @@ Ignore linting a file by adding an ignore comment at the top of the file:
fn repl_subcommand<'a, 'b>() -> App<'a, 'b> {
runtime_args(SubCommand::with_name("repl"), false, true)
.about("Read Eval Print Loop")
+ .arg(
+ Arg::with_name("eval")
+ .long("eval")
+ .help("Evaluates the provided code when the REPL starts.")
+ .takes_value(true)
+ .value_name("code"),
+ )
}
fn run_subcommand<'a, 'b>() -> App<'a, 'b> {
@@ -1701,7 +1710,9 @@ fn lint_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
fn repl_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
runtime_args_parse(flags, matches, false, true);
flags.repl = true;
- flags.subcommand = DenoSubcommand::Repl;
+ flags.subcommand = DenoSubcommand::Repl {
+ eval: matches.value_of("eval").map(ToOwned::to_owned),
+ };
flags.allow_net = Some(vec![]);
flags.allow_env = Some(vec![]);
flags.allow_run = Some(vec![]);
@@ -2706,7 +2717,7 @@ mod tests {
r.unwrap(),
Flags {
repl: true,
- subcommand: DenoSubcommand::Repl,
+ subcommand: DenoSubcommand::Repl { eval: None },
allow_net: Some(vec![]),
allow_env: Some(vec![]),
allow_run: Some(vec![]),
@@ -2727,7 +2738,7 @@ mod tests {
r.unwrap(),
Flags {
repl: true,
- subcommand: DenoSubcommand::Repl,
+ subcommand: DenoSubcommand::Repl { eval: None },
import_map_path: Some("import_map.json".to_string()),
no_remote: true,
config_path: Some("tsconfig.json".to_string()),
@@ -2754,6 +2765,29 @@ mod tests {
}
#[test]
+ fn repl_with_eval_flag() {
+ #[rustfmt::skip]
+ let r = flags_from_vec(svec!["deno", "repl", "--eval", "console.log('hello');"]);
+ assert_eq!(
+ r.unwrap(),
+ Flags {
+ repl: true,
+ subcommand: DenoSubcommand::Repl {
+ eval: Some("console.log('hello');".to_string()),
+ },
+ allow_net: Some(vec![]),
+ allow_env: Some(vec![]),
+ allow_run: Some(vec![]),
+ allow_read: Some(vec![]),
+ allow_write: Some(vec![]),
+ allow_plugin: true,
+ allow_hrtime: true,
+ ..Flags::default()
+ }
+ );
+ }
+
+ #[test]
fn allow_read_allowlist() {
use tempfile::TempDir;
let temp_dir = TempDir::new().expect("tempdir fail").path().to_path_buf();