mirror of
https://github.com/denoland/deno.git
synced 2025-01-03 12:58:54 -05:00
fix(cli): support passing cli arguments under deno eval
(#8547)
Fixes #8538
This commit is contained in:
parent
973af61d8b
commit
b6bfc32f8d
1 changed files with 48 additions and 2 deletions
50
cli/flags.rs
50
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> {
|
||||
|
@ -2204,6 +2220,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"]);
|
||||
|
|
Loading…
Reference in a new issue