From 7135d34ccab7629da57c75ee239fcb0dda733eae Mon Sep 17 00:00:00 2001 From: crowlKats <13135287+crowlKats@users.noreply.github.com> Date: Sun, 6 Dec 2020 18:19:21 +0100 Subject: [PATCH] refactor(cli): remove Option from Flags.v8_flags (#8633) --- cli/flags.rs | 40 +++++++++++++++------------------------- cli/main.rs | 4 ++-- cli/tools/installer.rs | 4 ++-- 3 files changed, 19 insertions(+), 29 deletions(-) diff --git a/cli/flags.rs b/cli/flags.rs index c5c6f47f16..5ff21971d2 100644 --- a/cli/flags.rs +++ b/cli/flags.rs @@ -11,11 +11,6 @@ use std::net::SocketAddr; use std::path::PathBuf; use std::str::FromStr; -/// Creates vector of strings, Vec -macro_rules! svec { - ($($x:expr),*) => (vec![$($x.to_string()),*]); -} - #[derive(Clone, Debug, PartialEq)] pub enum DenoSubcommand { Bundle { @@ -129,7 +124,7 @@ pub struct Flags { pub repl: bool, pub seed: Option, pub unstable: bool, - pub v8_flags: Option>, + pub v8_flags: Vec, pub version: bool, pub watch: bool, pub write_allowlist: Vec, @@ -1465,8 +1460,7 @@ fn v8_flags_arg<'a, 'b>() -> Arg<'a, 'b> { fn v8_flags_arg_parse(flags: &mut Flags, matches: &ArgMatches) { if let Some(v8_flags) = matches.values_of("v8-flags") { - let s: Vec = v8_flags.map(String::from).collect(); - flags.v8_flags = Some(s); + flags.v8_flags = v8_flags.map(String::from).collect(); } } @@ -1501,16 +1495,7 @@ fn seed_arg_parse(flags: &mut Flags, matches: &ArgMatches) { let seed = seed_string.parse::().unwrap(); flags.seed = Some(seed); - let v8_seed_flag = format!("--random-seed={}", seed); - - match flags.v8_flags { - Some(ref mut v8_flags) => { - v8_flags.push(v8_seed_flag); - } - None => { - flags.v8_flags = Some(svec![v8_seed_flag]); - } - } + flags.v8_flags.push(format!("--random-seed={}", seed)); } } @@ -1631,6 +1616,11 @@ pub fn resolve_urls(urls: Vec) -> Vec { mod tests { use super::*; + /// Creates vector of strings, Vec + macro_rules! svec { + ($($x:expr),*) => (vec![$($x.to_string()),*]); +} + #[test] fn global_flags() { #[rustfmt::skip] @@ -1752,7 +1742,7 @@ mod tests { subcommand: DenoSubcommand::Run { script: "_".to_string(), }, - v8_flags: Some(svec!["--help"]), + v8_flags: svec!["--help"], ..Flags::default() } ); @@ -1769,7 +1759,7 @@ mod tests { subcommand: DenoSubcommand::Run { script: "script.ts".to_string(), }, - v8_flags: Some(svec!["--expose-gc", "--gc-stats=1"]), + v8_flags: svec!["--expose-gc", "--gc-stats=1"], ..Flags::default() } ); @@ -2256,7 +2246,7 @@ mod tests { lock_write: true, ca_file: Some("example.crt".to_string()), cached_only: true, - v8_flags: Some(svec!["--help", "--random-seed=1"]), + v8_flags: svec!["--help", "--random-seed=1"], seed: Some(1), inspect: Some("127.0.0.1:9229".parse().unwrap()), allow_net: true, @@ -2340,7 +2330,7 @@ mod tests { lock_write: true, ca_file: Some("example.crt".to_string()), cached_only: true, - v8_flags: Some(svec!["--help", "--random-seed=1"]), + v8_flags: svec!["--help", "--random-seed=1"], seed: Some(1), inspect: Some("127.0.0.1:9229".parse().unwrap()), allow_net: true, @@ -2681,7 +2671,7 @@ mod tests { script: "script.ts".to_string(), }, seed: Some(250_u64), - v8_flags: Some(svec!["--random-seed=250"]), + v8_flags: svec!["--random-seed=250"], ..Flags::default() } ); @@ -2704,7 +2694,7 @@ mod tests { script: "script.ts".to_string(), }, seed: Some(250_u64), - v8_flags: Some(svec!["--expose-gc", "--random-seed=250"]), + v8_flags: svec!["--expose-gc", "--random-seed=250"], ..Flags::default() } ); @@ -2756,7 +2746,7 @@ mod tests { lock_write: true, ca_file: Some("example.crt".to_string()), cached_only: true, - v8_flags: Some(svec!["--help", "--random-seed=1"]), + v8_flags: svec!["--help", "--random-seed=1"], seed: Some(1), inspect: Some("127.0.0.1:9229".parse().unwrap()), allow_net: true, diff --git a/cli/main.rs b/cli/main.rs index 916248e4c8..e297d0c4c7 100644 --- a/cli/main.rs +++ b/cli/main.rs @@ -1051,8 +1051,8 @@ pub fn main() { } let flags = flags::flags_from_vec(args); - if let Some(ref v8_flags) = flags.v8_flags { - init_v8_flags(v8_flags); + if !flags.v8_flags.is_empty() { + init_v8_flags(&*flags.v8_flags); } init_logger(flags.log_level); diff --git a/cli/tools/installer.rs b/cli/tools/installer.rs index f2f5562c2c..ec527949d1 100644 --- a/cli/tools/installer.rs +++ b/cli/tools/installer.rs @@ -227,8 +227,8 @@ pub fn install( executable_args.push("--cached_only".to_string()); } - if let Some(v8_flags) = flags.v8_flags { - executable_args.push(format!("--v8-flags={}", v8_flags.join(","))); + if !flags.v8_flags.is_empty() { + executable_args.push(format!("--v8-flags={}", flags.v8_flags.join(","))); } if let Some(seed) = flags.seed {