From 3f9c869f27cd10c3c53c63ed7d64eb60cf6f3335 Mon Sep 17 00:00:00 2001 From: Chris Olszewski Date: Fri, 30 Aug 2024 16:44:02 -0400 Subject: [PATCH] fix(daemon): use correct arg group for deciding daemon config (#9088) ### Description https://github.com/vercel/turborepo/pull/8728 accidentally disconnected the `--no-daemon` and `--daemon` flags. The config was populated using `args.run_args` which is explicitly set to `None` for all `run` commands [here](https://github.com/vercel/turborepo/blob/main/crates/turborepo-lib/src/cli/mod.rs#L1044). This resulted in the config never getting the flag values. ### Testing Instructions Before ``` [0 olszewski@chriss-mbp] /tmp/turbo-bug $ turbo_dev run build --no-daemon -vv 2>&1 | rg turbod 2024-08-30T16:05:12.441-0400 [DEBUG] turborepo_lib::run::builder: skipping turbod since we appear to be in a non-interactive context [0 olszewski@chriss-mbp] /tmp/turbo-bug $ turbo_dev run build --daemon -vv 2>&1 | rg turbod 2024-08-30T16:05:23.639-0400 [DEBUG] turborepo_lib::run::builder: skipping turbod since we appear to be in a non-interactive context ``` After ``` [1 olszewski@chriss-mbp] /tmp/turbo-bug $ turbo_dev run build --no-daemon -vv 2>&1 | rg turbod 2024-08-30T15:59:27.083-0400 [DEBUG] turborepo_lib::run::builder: skipping turbod since --no-daemon was passed [0 olszewski@chriss-mbp] /tmp/turbo-bug $ turbo_dev run build --daemon -vv 2>&1 | rg turbod 2024-08-30T15:59:34.093-0400 [DEBUG] turborepo_lib::daemon::connector: looking for pid in lockfile: AbsoluteSystemPathBuf("/var/folders/3m/rxkycvgs5jgfvs0k9xcgp6km0000gn/T/turbod/5e203d2ff6cb65bf/turbod.pid") ``` --- crates/turborepo-lib/src/cli/mod.rs | 15 +++++++++++++-- crates/turborepo-lib/src/commands/mod.rs | 2 +- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/crates/turborepo-lib/src/cli/mod.rs b/crates/turborepo-lib/src/cli/mod.rs index 9f2836558763b..49016564a71df 100644 --- a/crates/turborepo-lib/src/cli/mod.rs +++ b/crates/turborepo-lib/src/cli/mod.rs @@ -223,7 +223,9 @@ pub struct Args { #[clap(long, global = true)] pub dangerously_disable_package_manager_check: bool, #[clap(flatten, next_help_heading = "Run Arguments")] - pub run_args: Option, + // DO NOT MAKE THIS VISIBLE + // This is explicitly set to None in `run` + run_args: Option, // This should be inside `RunArgs` but clap currently has a bug // around nested flattened optional args: https://github.com/clap-rs/clap/issues/4697 #[clap(flatten)] @@ -459,6 +461,15 @@ impl Args { ); } } + + /// Fetch the run args supplied to the command + pub fn run_args(&self) -> Option<&RunArgs> { + if let Some(Command::Run { run_args, .. }) = &self.command { + Some(run_args) + } else { + self.run_args.as_ref() + } + } } /// Defines the subcommands for CLI. NOTE: If we change the commands in Go, @@ -1041,7 +1052,7 @@ pub async fn run( let mut command = if let Some(command) = mem::take(&mut cli_args.command) { command } else { - let run_args = cli_args.run_args.take().unwrap_or_default(); + let run_args = cli_args.run_args.clone().unwrap_or_default(); let execution_args = cli_args .execution_args // We clone instead of take as take would leave the command base a copy of cli_args diff --git a/crates/turborepo-lib/src/commands/mod.rs b/crates/turborepo-lib/src/commands/mod.rs index 12d8c43958c72..37fc8f52f847f 100644 --- a/crates/turborepo-lib/src/commands/mod.rs +++ b/crates/turborepo-lib/src/commands/mod.rs @@ -88,7 +88,7 @@ impl CommandBase { .dangerously_disable_package_manager_check .then_some(true), ) - .with_daemon(self.args.run_args.as_ref().and_then(|args| args.daemon())) + .with_daemon(self.args.run_args().and_then(|args| args.daemon())) .with_env_mode( self.args .command