diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2024-01-22 18:37:28 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-22 17:37:28 +0000 |
commit | d20c9e75d1540b1a27e721d0cf66d29ba6a2c3fb (patch) | |
tree | 83059b5759fad286d8131795d7d79d6fee5bb440 /cli/args/flags.rs | |
parent | bc92f872988fd8b9cdf2ae1479278789911237a5 (diff) |
refactor: add "UnstableConfig" struct to cli/args/flags.rs (#21993)
This commit adds "UnstableConfig" struct which centralizes
handling of all "--unstable-*" flags.
Closes https://github.com/denoland/deno/issues/21920
Diffstat (limited to 'cli/args/flags.rs')
-rw-r--r-- | cli/args/flags.rs | 57 |
1 files changed, 36 insertions, 21 deletions
diff --git a/cli/args/flags.rs b/cli/args/flags.rs index 46560b9ba..3810d77a3 100644 --- a/cli/args/flags.rs +++ b/cli/args/flags.rs @@ -405,6 +405,17 @@ pub enum CaData { Bytes(Vec<u8>), } +#[derive( + Clone, Default, Debug, Eq, PartialEq, serde::Serialize, serde::Deserialize, +)] +pub struct UnstableConfig { + pub legacy_flag_enabled: bool, // --unstable + pub bare_node_builtins: bool, // --unstable-bare-node-builts + pub byonm: bool, + pub sloppy_imports: bool, + pub features: Vec<String>, // --unstabe-kv --unstable-cron +} + #[derive(Clone, Debug, Eq, PartialEq, Default)] pub struct Flags { /// Vector of CLI arguments - these are user script arguments, all Deno @@ -460,12 +471,7 @@ pub struct Flags { pub reload: bool, pub seed: Option<u64>, pub strace_ops: Option<Vec<String>>, - pub unstable: bool, - pub unstable_bare_node_builtins: bool, - pub unstable_byonm: bool, - pub unstable_sloppy_imports: bool, - pub unstable_workspaces: bool, - pub unstable_features: Vec<String>, + pub unstable_config: UnstableConfig, pub unsafely_ignore_certificate_errors: Option<Vec<String>>, pub v8_flags: Vec<String>, } @@ -865,19 +871,20 @@ pub fn flags_from_vec(args: Vec<String>) -> clap::error::Result<Flags> { let mut flags = Flags::default(); if matches.get_flag("unstable") { - flags.unstable = true; + flags.unstable_config.legacy_flag_enabled = true; } for (name, _, _) in crate::UNSTABLE_GRANULAR_FLAGS { if matches.get_flag(&format!("unstable-{}", name)) { - flags.unstable_features.push(name.to_string()); + flags.unstable_config.features.push(name.to_string()); } } - flags.unstable_bare_node_builtins = + flags.unstable_config.bare_node_builtins = matches.get_flag("unstable-bare-node-builtins"); - flags.unstable_byonm = matches.get_flag("unstable-byonm"); - flags.unstable_sloppy_imports = matches.get_flag("unstable-sloppy-imports"); + flags.unstable_config.byonm = matches.get_flag("unstable-byonm"); + flags.unstable_config.sloppy_imports = + matches.get_flag("unstable-sloppy-imports"); if matches.get_flag("quiet") { flags.log_level = Some(Level::Error); @@ -4199,7 +4206,10 @@ mod tests { subcommand: DenoSubcommand::Run(RunFlags::new_default( "script.ts".to_string() )), - unstable: true, + unstable_config: UnstableConfig { + legacy_flag_enabled: true, + ..Default::default() + }, log_level: Some(Level::Error), ..Flags::default() } @@ -7054,7 +7064,10 @@ mod tests { reporter: Default::default(), junit_path: None, }), - unstable: true, + unstable_config: UnstableConfig { + legacy_flag_enabled: true, + ..Default::default() + }, no_prompt: true, no_npm: true, no_remote: true, @@ -8189,7 +8202,10 @@ mod tests { cwd: None, task: Some("build".to_string()), }), - unstable: true, + unstable_config: UnstableConfig { + legacy_flag_enabled: true, + ..Default::default() + }, log_level: Some(log::Level::Error), ..Flags::default() } @@ -8286,7 +8302,10 @@ mod tests { }, watch: Default::default(), }), - unstable: true, + unstable_config: UnstableConfig { + legacy_flag_enabled: true, + ..Default::default() + }, no_npm: true, no_remote: true, type_check_mode: TypeCheckMode::Local, @@ -8430,7 +8449,7 @@ mod tests { #[test] fn jupyter() { - let r = flags_from_vec(svec!["deno", "jupyter", "--unstable"]); + let r = flags_from_vec(svec!["deno", "jupyter"]); assert_eq!( r.unwrap(), Flags { @@ -8439,12 +8458,11 @@ mod tests { kernel: false, conn_file: None, }), - unstable: true, ..Flags::default() } ); - let r = flags_from_vec(svec!["deno", "jupyter", "--unstable", "--install"]); + let r = flags_from_vec(svec!["deno", "jupyter", "--install"]); assert_eq!( r.unwrap(), Flags { @@ -8453,7 +8471,6 @@ mod tests { kernel: false, conn_file: None, }), - unstable: true, ..Flags::default() } ); @@ -8461,7 +8478,6 @@ mod tests { let r = flags_from_vec(svec![ "deno", "jupyter", - "--unstable", "--kernel", "--conn", "path/to/conn/file" @@ -8474,7 +8490,6 @@ mod tests { kernel: true, conn_file: Some(PathBuf::from("path/to/conn/file")), }), - unstable: true, ..Flags::default() } ); |