summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cli/flags.rs50
1 files changed, 48 insertions, 2 deletions
diff --git a/cli/flags.rs b/cli/flags.rs
index 740cec790..a8a4ddba2 100644
--- a/cli/flags.rs
+++ b/cli/flags.rs
@@ -464,9 +464,19 @@ fn eval_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
flags.allow_write = true;
flags.allow_plugin = true;
flags.allow_hrtime = true;
- let code = matches.value_of("code").unwrap().to_string();
let as_typescript = matches.is_present("ts");
let print = matches.is_present("print");
+ let mut code: Vec<String> = matches
+ .values_of("code_arg")
+ .unwrap()
+ .map(String::from)
+ .collect();
+ assert!(!code.is_empty());
+ let code_args = code.split_off(1);
+ let code = code[0].to_string();
+ for v in code_args {
+ flags.argv.push(v);
+ }
flags.subcommand = DenoSubcommand::Eval {
print,
code,
@@ -855,7 +865,13 @@ This command has implicit access to all permissions (--allow-all).",
.takes_value(false)
.multiple(false),
)
- .arg(Arg::with_name("code").takes_value(true).required(true))
+ .arg(
+ Arg::with_name("code_arg")
+ .multiple(true)
+ .help("Code arg")
+ .value_name("CODE_ARG")
+ .required(true),
+ )
}
fn info_subcommand<'a, 'b>() -> App<'a, 'b> {
@@ -2205,6 +2221,36 @@ mod tests {
}
#[test]
+ fn eval_args() {
+ let r = flags_from_vec_safe(svec![
+ "deno",
+ "eval",
+ "console.log(Deno.args)",
+ "arg1",
+ "arg2"
+ ]);
+ assert_eq!(
+ r.unwrap(),
+ Flags {
+ subcommand: DenoSubcommand::Eval {
+ print: false,
+ code: "console.log(Deno.args)".to_string(),
+ as_typescript: false,
+ },
+ argv: svec!["arg1", "arg2"],
+ allow_net: true,
+ allow_env: true,
+ allow_run: true,
+ allow_read: true,
+ allow_write: true,
+ allow_plugin: true,
+ allow_hrtime: true,
+ ..Flags::default()
+ }
+ );
+ }
+
+ #[test]
fn repl() {
let r = flags_from_vec_safe(svec!["deno"]);
assert_eq!(