From fa63fd4610fbe4a1d95c4da776e4a1cfa8f8e0b9 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Thu, 15 Jun 2023 13:09:37 -0400 Subject: refactor(flags): move watch flags into subcommand structs (#19516) Moves the watch setting out of the `Flags` struct and into the individual subcommands --- cli/tools/run.rs | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'cli/tools/run.rs') 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 { +pub async fn run_script( + flags: Flags, + run_flags: RunFlags, +) -> Result { 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 { // TODO(bartlomieju): this function is not handling `exit_code` set by the runtime // code properly. -async fn run_with_watch(flags: Flags) -> Result { - let clear_screen = !flags.no_clear_screen; - +async fn run_with_watch( + flags: Flags, + watch_flags: WatchFlagsWithPaths, +) -> Result { 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 { 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(), -- cgit v1.2.3