From fbbb4d0fbbfa1e4983aa34b90827acf4adfd18ec Mon Sep 17 00:00:00 2001 From: Chris Olszewski Date: Wed, 5 Jun 2024 18:02:07 -0700 Subject: [PATCH] fix(ui): disable TUI if log order is specified --- crates/turborepo-lib/src/cli/mod.rs | 20 +++++++++++++++++++- crates/turborepo-lib/src/commands/mod.rs | 9 +++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/crates/turborepo-lib/src/cli/mod.rs b/crates/turborepo-lib/src/cli/mod.rs index 2a6d54d361850..f9a2473ab352a 100644 --- a/crates/turborepo-lib/src/cli/mod.rs +++ b/crates/turborepo-lib/src/cli/mod.rs @@ -105,6 +105,14 @@ impl Display for LogOrder { } } +impl LogOrder { + pub fn compatible_with_tui(&self) -> bool { + // If the user requested a specific order to the logs, then this isn't + // compatible with the TUI and means we cannot use it. + matches!(self, Self::Auto) + } +} + #[derive(Copy, Clone, Debug, PartialEq, Serialize, ValueEnum)] pub enum DryRunMode { Text, @@ -949,6 +957,7 @@ pub async fn run( #[allow(unused_variables)] logger: &TurboSubscriber, ui: UI, ) -> Result { + // TODO: remove mutability from this function let mut cli_args = Args::new(); let version = get_version(); @@ -979,7 +988,9 @@ pub async fn run( let run_args = cli_args.run_args.take().unwrap_or_default(); let execution_args = cli_args .execution_args - .take() + // We clone instead of take as take would leave the command base a copy of cli_args + // missing any execution args. + .clone() .ok_or_else(|| Error::NoCommand(Backtrace::capture()))?; if execution_args.tasks.is_empty() { let mut cmd = ::command(); @@ -2554,4 +2565,11 @@ mod test { ); assert!(Args::try_parse_from(["turbo", "build", "--preflight=true"]).is_err()); } + + #[test] + fn test_log_stream_tui_compatibility() { + assert!(LogOrder::Auto.compatible_with_tui()); + assert!(!LogOrder::Stream.compatible_with_tui()); + assert!(!LogOrder::Grouped.compatible_with_tui()); + } } diff --git a/crates/turborepo-lib/src/commands/mod.rs b/crates/turborepo-lib/src/commands/mod.rs index 5788a2c7725ec..34ad240559a1d 100644 --- a/crates/turborepo-lib/src/commands/mod.rs +++ b/crates/turborepo-lib/src/commands/mod.rs @@ -68,6 +68,15 @@ impl CommandBase { .with_token(self.args.token.clone()) .with_timeout(self.args.remote_cache_timeout) .with_preflight(self.args.preflight.then_some(true)) + .with_ui(self.args.execution_args.as_ref().and_then(|args| { + if !args.log_order.compatible_with_tui() { + Some(false) + } else { + // If the argument is compatible with the TUI this does not mean we should + // override other configs + None + } + })) .build() }