diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2023-06-15 13:09:37 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-15 13:09:37 -0400 |
commit | fa63fd4610fbe4a1d95c4da776e4a1cfa8f8e0b9 (patch) | |
tree | c23b95ed50ed20351b543c900cc970cd9e382ac1 /cli/tools | |
parent | b2e546e530374ca9456aa3f6ff195c3384b32f24 (diff) |
refactor(flags): move watch flags into subcommand structs (#19516)
Moves the watch setting out of the `Flags` struct and into the
individual subcommands
Diffstat (limited to 'cli/tools')
-rw-r--r-- | cli/tools/bench.rs | 11 | ||||
-rw-r--r-- | cli/tools/bundle.rs | 11 | ||||
-rw-r--r-- | cli/tools/fmt.rs | 5 | ||||
-rw-r--r-- | cli/tools/lint.rs | 5 | ||||
-rw-r--r-- | cli/tools/run.rs | 24 | ||||
-rw-r--r-- | cli/tools/test.rs | 11 |
6 files changed, 33 insertions, 34 deletions
diff --git a/cli/tools/bench.rs b/cli/tools/bench.rs index 318ac4f36..f926cec5a 100644 --- a/cli/tools/bench.rs +++ b/cli/tools/bench.rs @@ -684,12 +684,15 @@ pub async fn run_benchmarks_with_watch( flags: Flags, bench_flags: BenchFlags, ) -> Result<(), AnyError> { - let clear_screen = !flags.no_clear_screen; file_watcher::watch_func( flags, file_watcher::PrintConfig { job_name: "Bench".to_string(), - clear_screen, + clear_screen: bench_flags + .watch + .as_ref() + .map(|w| !w.no_clear_screen) + .unwrap_or(true), }, move |flags, sender, changed_paths| { let bench_flags = bench_flags.clone(); @@ -701,9 +704,7 @@ pub async fn run_benchmarks_with_watch( let cli_options = factory.cli_options(); let bench_options = cli_options.resolve_bench_options(bench_flags)?; - if let Some(watch_paths) = cli_options.watch_paths() { - let _ = sender.send(watch_paths); - } + let _ = sender.send(cli_options.watch_paths()); let _ = sender.send(bench_options.files.include.clone()); let graph_kind = cli_options.type_check_mode().as_graph_kind(); diff --git a/cli/tools/bundle.rs b/cli/tools/bundle.rs index 1800d03cc..dc944d646 100644 --- a/cli/tools/bundle.rs +++ b/cli/tools/bundle.rs @@ -28,13 +28,12 @@ pub async fn bundle( "Use alternative bundlers like \"deno_emit\", \"esbuild\" or \"rollup\" instead." ); - if flags.watch.is_some() { - let clear_screen = !flags.no_clear_screen; + if let Some(watch_flags) = &bundle_flags.watch { util::file_watcher::watch_func( flags, util::file_watcher::PrintConfig { job_name: "Bundle".to_string(), - clear_screen, + clear_screen: !watch_flags.no_clear_screen, }, move |flags, sender, _changed_paths| { let bundle_flags = bundle_flags.clone(); @@ -44,11 +43,7 @@ pub async fn bundle( .build_from_flags(flags) .await?; let cli_options = factory.cli_options(); - - if let Some(watch_paths) = cli_options.watch_paths() { - let _ = sender.send(watch_paths); - } - + let _ = sender.send(cli_options.watch_paths()); bundle_action(factory, &bundle_flags).await?; Ok(()) diff --git a/cli/tools/fmt.rs b/cli/tools/fmt.rs index 7116c78cc..d7a235b4a 100644 --- a/cli/tools/fmt.rs +++ b/cli/tools/fmt.rs @@ -61,13 +61,12 @@ pub async fn format(flags: Flags, fmt_flags: FmtFlags) -> Result<(), AnyError> { ); } - if flags.watch.is_some() { - let clear_screen = !flags.no_clear_screen; + if let Some(watch_flags) = &fmt_flags.watch { file_watcher::watch_func( flags, file_watcher::PrintConfig { job_name: "Fmt".to_string(), - clear_screen, + clear_screen: !watch_flags.no_clear_screen, }, move |flags, sender, changed_paths| { let fmt_flags = fmt_flags.clone(); diff --git a/cli/tools/lint.rs b/cli/tools/lint.rs index 9bfe1fd16..4a622f0a0 100644 --- a/cli/tools/lint.rs +++ b/cli/tools/lint.rs @@ -51,18 +51,17 @@ fn create_reporter(kind: LintReporterKind) -> Box<dyn LintReporter + Send> { } pub async fn lint(flags: Flags, lint_flags: LintFlags) -> Result<(), AnyError> { - if flags.watch.is_some() { + if let Some(watch_flags) = &lint_flags.watch { if lint_flags.is_stdin() { return Err(generic_error( "Lint watch on standard input is not supported.", )); } - let clear_screen = !flags.no_clear_screen; file_watcher::watch_func( flags, file_watcher::PrintConfig { job_name: "Lint".to_string(), - clear_screen, + clear_screen: !watch_flags.no_clear_screen, }, move |flags, sender, changed_paths| { let lint_flags = lint_flags.clone(); diff --git a/cli/tools/run.rs b/cli/tools/run.rs index cbc9c3eae..bc55f3ead 100644 --- a/cli/tools/run.rs +++ b/cli/tools/run.rs @@ -9,12 +9,17 @@ use deno_runtime::permissions::PermissionsContainer; use crate::args::EvalFlags; use crate::args::Flags; +use crate::args::RunFlags; +use crate::args::WatchFlagsWithPaths; use crate::factory::CliFactory; use crate::factory::CliFactoryBuilder; use crate::file_fetcher::File; use crate::util; -pub async fn run_script(flags: Flags) -> Result<i32, AnyError> { +pub async fn run_script( + flags: Flags, + run_flags: RunFlags, +) -> Result<i32, AnyError> { if !flags.has_permission() && flags.has_permission_in_argv() { log::warn!( "{}", @@ -26,8 +31,8 @@ To grant permissions, set them before the script argument. For example: ); } - if flags.watch.is_some() { - return run_with_watch(flags).await; + if let Some(watch_flags) = run_flags.watch { + return run_with_watch(flags, watch_flags).await; } // TODO(bartlomieju): actually I think it will also fail if there's an import @@ -96,14 +101,15 @@ pub async fn run_from_stdin(flags: Flags) -> Result<i32, AnyError> { // TODO(bartlomieju): this function is not handling `exit_code` set by the runtime // code properly. -async fn run_with_watch(flags: Flags) -> Result<i32, AnyError> { - let clear_screen = !flags.no_clear_screen; - +async fn run_with_watch( + flags: Flags, + watch_flags: WatchFlagsWithPaths, +) -> Result<i32, AnyError> { util::file_watcher::watch_func( flags, util::file_watcher::PrintConfig { job_name: "Process".to_string(), - clear_screen, + clear_screen: !watch_flags.no_clear_screen, }, move |flags, sender, _changed_paths| { Ok(async move { @@ -116,9 +122,7 @@ async fn run_with_watch(flags: Flags) -> Result<i32, AnyError> { maybe_npm_install(&factory).await?; - if let Some(watch_paths) = cli_options.watch_paths() { - let _ = sender.send(watch_paths); - } + let _ = sender.send(cli_options.watch_paths()); let permissions = PermissionsContainer::new(Permissions::from_options( &cli_options.permissions_options(), diff --git a/cli/tools/test.rs b/cli/tools/test.rs index 159de8ec8..dc48ab9e5 100644 --- a/cli/tools/test.rs +++ b/cli/tools/test.rs @@ -1726,12 +1726,15 @@ pub async fn run_tests_with_watch( } }); - let clear_screen = !flags.no_clear_screen; file_watcher::watch_func( flags, file_watcher::PrintConfig { job_name: "Test".to_string(), - clear_screen, + clear_screen: !test_flags + .watch + .as_ref() + .map(|w| !w.no_clear_screen) + .unwrap_or(true), }, move |flags, sender, changed_paths| { let test_flags = test_flags.clone(); @@ -1743,9 +1746,7 @@ pub async fn run_tests_with_watch( let cli_options = factory.cli_options(); let test_options = cli_options.resolve_test_options(test_flags)?; - if let Some(watch_paths) = cli_options.watch_paths() { - let _ = sender.send(watch_paths); - } + let _ = sender.send(cli_options.watch_paths()); let _ = sender.send(test_options.files.include.clone()); let graph_kind = cli_options.type_check_mode().as_graph_kind(); |