From 6291ac82ee75481f04cf6ce3da782e5dd20cf693 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=A8=E6=9D=89?= Date: Wed, 1 Apr 2020 21:35:34 +0800 Subject: fix(#4554): use --inspect in repl & eval (#4562) --- cli/flags.rs | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 2 deletions(-) (limited to 'cli') diff --git a/cli/flags.rs b/cli/flags.rs index d90f1f3b9..80484756d 100644 --- a/cli/flags.rs +++ b/cli/flags.rs @@ -406,6 +406,7 @@ fn completions_parse(flags: &mut Flags, matches: &clap::ArgMatches) { fn repl_parse(flags: &mut Flags, matches: &clap::ArgMatches) { v8_flags_arg_parse(flags, matches); ca_file_arg_parse(flags, matches); + inspect_arg_parse(flags, matches); flags.subcommand = DenoSubcommand::Repl; flags.allow_net = true; flags.allow_env = true; @@ -419,6 +420,7 @@ fn repl_parse(flags: &mut Flags, matches: &clap::ArgMatches) { fn eval_parse(flags: &mut Flags, matches: &clap::ArgMatches) { v8_flags_arg_parse(flags, matches); ca_file_arg_parse(flags, matches); + inspect_arg_parse(flags, matches); flags.allow_net = true; flags.allow_env = true; flags.allow_run = true; @@ -612,7 +614,7 @@ Format stdin and write to stdout: } fn repl_subcommand<'a, 'b>() -> App<'a, 'b> { - SubCommand::with_name("repl") + inspect_args(SubCommand::with_name("repl")) .about("Read Eval Print Loop") .arg(v8_flags_arg()) .arg(ca_file_arg()) @@ -692,7 +694,7 @@ fn completions_subcommand<'a, 'b>() -> App<'a, 'b> { } fn eval_subcommand<'a, 'b>() -> App<'a, 'b> { - SubCommand::with_name("eval") + inspect_args(SubCommand::with_name("eval")) .arg(ca_file_arg()) .about("Eval script") .long_about( @@ -2352,6 +2354,34 @@ fn eval_with_cafile() { ); } +#[test] +fn eval_with_inspect() { + let r = flags_from_vec_safe(svec![ + "deno", + "eval", + "--inspect", + "const foo = 'bar'" + ]); + assert_eq!( + r.unwrap(), + Flags { + subcommand: DenoSubcommand::Eval { + code: "const foo = 'bar'".to_string(), + as_typescript: false, + }, + inspect: Some("127.0.0.1:9229".to_string()), + 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 fetch_with_cafile() { let r = flags_from_vec_safe(svec![ @@ -2441,6 +2471,26 @@ fn repl_with_cafile() { ); } +#[test] +fn repl_with_inspect() { + let r = flags_from_vec_safe(svec!["deno", "repl", "--inspect"]); + assert_eq!( + r.unwrap(), + Flags { + subcommand: DenoSubcommand::Repl {}, + inspect: Some("127.0.0.1:9229".to_string()), + allow_read: true, + allow_write: true, + allow_net: true, + allow_env: true, + allow_run: true, + allow_plugin: true, + allow_hrtime: true, + ..Flags::default() + } + ); +} + #[test] fn doc() { let r = -- cgit v1.2.3