diff --git a/crates/core/src/commands/common.rs b/crates/core/src/commands/common.rs index b155876..0d191c0 100644 --- a/crates/core/src/commands/common.rs +++ b/crates/core/src/commands/common.rs @@ -45,9 +45,14 @@ pub async fn push( ]); let child = run_command_with_env( - &CommandArguments::new(command_string, context.modifiers).mode( - crate::commands::ChildOutputMode::Nix(Some(context.name.clone())), - ), + &CommandArguments::new( + command_string, + context.modifiers, + Some(context.name.clone()), + ) + .mode(crate::commands::ChildOutputMode::Nix(Some( + context.name.clone(), + ))), HashMap::from([( "NIX_SSHOPTS".into(), target.create_ssh_opts(context.modifiers)?, @@ -153,7 +158,7 @@ pub async fn evaluate_hive_attribute( command_string.arg(&attribute); let child = run_command( - &CommandArguments::new(command_string, modifiers) + &CommandArguments::new(command_string, modifiers, None) .mode(crate::commands::ChildOutputMode::Nix(None)), ) .await?; diff --git a/crates/core/src/commands/mod.rs b/crates/core/src/commands/mod.rs index 7953246..7e208e9 100644 --- a/crates/core/src/commands/mod.rs +++ b/crates/core/src/commands/mod.rs @@ -36,7 +36,7 @@ static AT_NIX_FINDER: LazyLock = #[derive(Clone, Debug)] pub(crate) enum ChildOutputMode { Nix(Option), - Generic, + Generic(Option), } #[derive(Debug)] @@ -58,14 +58,18 @@ pub(crate) struct CommandArguments> { } impl> CommandArguments { - pub(crate) fn new(command_string: S, modifiers: SubCommandModifiers) -> Self { + pub(crate) fn new( + command_string: S, + modifiers: SubCommandModifiers, + name: Option, + ) -> Self { Self { command_string, keep_stdin_open: false, privilege_escalation_command: None, log_stdout: false, target: None, - output_mode: ChildOutputMode::Generic, + output_mode: ChildOutputMode::Generic(name), modifiers, build_name_map: Arc::new(Mutex::new(HashMap::new())), } @@ -255,10 +259,21 @@ impl ChildOutputMode { print_build_logs: bool, ) -> Option { let (slice, name) = match self { - Self::Generic => { + Self::Generic(name) => { let string = String::from_utf8_lossy(line); let stripped = console::strip_ansi_codes(&string); warn!("{stripped}"); + + if let Some(name) = name + && let Some(sender) = UI_SENDER.get() + { + let _ = sender.send(UiMessage::ContextLogLine { + name, + log: stripped.to_string(), + build_name: None, + }); + } + return Some(string.to_string()); } Self::Nix(name) => { diff --git a/crates/core/src/commands/noninteractive.rs b/crates/core/src/commands/noninteractive.rs index 377d684..7770de5 100644 --- a/crates/core/src/commands/noninteractive.rs +++ b/crates/core/src/commands/noninteractive.rs @@ -50,7 +50,7 @@ pub async fn non_interactive_command_with_env + Sync>( "{command_string}{extra}", command_string = arguments.command_string.as_ref(), extra = match arguments.output_mode { - ChildOutputMode::Generic => "", + ChildOutputMode::Generic(..) => "", ChildOutputMode::Nix(..) => " --log-format internal-json", } ); diff --git a/crates/core/src/commands/pty/mod.rs b/crates/core/src/commands/pty/mod.rs index 5bdb476..124852b 100644 --- a/crates/core/src/commands/pty/mod.rs +++ b/crates/core/src/commands/pty/mod.rs @@ -117,7 +117,7 @@ pub async fn interactive_command_with_env + Sync>( command = arguments.command_string.as_ref(), flags = match arguments.output_mode { ChildOutputMode::Nix(..) => "--log-format internal-json", - ChildOutputMode::Generic => "", + ChildOutputMode::Generic(..) => "", }, starting = create_starting_segment(&needles.start), ending = create_ending_segment(&needles) diff --git a/crates/core/src/hive/mod.rs b/crates/core/src/hive/mod.rs index 8ebcd3b..278564a 100644 --- a/crates/core/src/hive/mod.rs +++ b/crates/core/src/hive/mod.rs @@ -294,11 +294,7 @@ impl HiveLocation { ]); command_string.arg(&uri); - let command = run_command( - &CommandArguments::new(command_string, modifiers) - .mode(crate::commands::ChildOutputMode::Generic), - ) - .await?; + let command = run_command(&CommandArguments::new(command_string, modifiers, None)).await?; let result = command .wait_till_success() diff --git a/crates/core/src/hive/node.rs b/crates/core/src/hive/node.rs index f0a7011..afac2f9 100644 --- a/crates/core/src/hive/node.rs +++ b/crates/core/src/hive/node.rs @@ -129,9 +129,7 @@ impl Target { command_string.arg("exit"); let output = run_command( - &CommandArguments::new(command_string, modifiers) - .log_stdout() - .mode(crate::commands::ChildOutputMode::Generic), + &CommandArguments::new(command_string, modifiers, Some(name.clone())).log_stdout(), ) .await?; diff --git a/crates/core/src/hive/steps/activate.rs b/crates/core/src/hive/steps/activate.rs index fcd4c4d..2f68605 100644 --- a/crates/core/src/hive/steps/activate.rs +++ b/crates/core/src/hive/steps/activate.rs @@ -79,7 +79,7 @@ impl SwitchToConfiguration { command_string.arg(built_path.to_absolute_path()); let child = run_command( - &CommandArguments::new(command_string, ctx.modifiers) + &CommandArguments::new(command_string, ctx.modifiers, Some(ctx.name.clone())) .mode(crate::commands::ChildOutputMode::Nix(Some( ctx.name.clone(), ))) @@ -128,7 +128,7 @@ impl ExecuteStep for SwitchToConfiguration { }); let child = run_command( - &CommandArguments::new(command_string, ctx.modifiers) + &CommandArguments::new(command_string, ctx.modifiers, Some(ctx.name.clone())) .execute_on_remote(self.target.clone()) .privileged(&self.privilege_escalation_command) .log_stdout(), @@ -152,7 +152,7 @@ impl ExecuteStep for SwitchToConfiguration { warn!("Rebooting {name}!", name = ctx.name); let reboot = run_command( - &CommandArguments::new("reboot now", ctx.modifiers) + &CommandArguments::new("reboot now", ctx.modifiers, Some(ctx.name.clone())) .log_stdout() .execute_on_remote(Some(target.clone())) .privileged(&self.privilege_escalation_command), diff --git a/crates/core/src/hive/steps/build.rs b/crates/core/src/hive/steps/build.rs index af4daa0..976f1d0 100644 --- a/crates/core/src/hive/steps/build.rs +++ b/crates/core/src/hive/steps/build.rs @@ -191,7 +191,7 @@ impl ExecuteStep for Build { command_string.arg(&attribute); let status = run_command_with_env( - &CommandArguments::new(command_string, ctx.modifiers) + &CommandArguments::new(command_string, ctx.modifiers, Some(ctx.name.clone())) // build remotely if asked for AND we isnt applying locally .execute_on_remote(match metadata { NixCommandBuildMetadata::Remotely { target, .. } => { diff --git a/crates/core/src/hive/steps/keys.rs b/crates/core/src/hive/steps/keys.rs index b1420b8..98a2cb9 100644 --- a/crates/core/src/hive/steps/keys.rs +++ b/crates/core/src/hive/steps/keys.rs @@ -253,7 +253,7 @@ impl ExecuteStep for Keys { )); let mut child = run_command( - &CommandArguments::new(command_string, ctx.modifiers) + &CommandArguments::new(command_string, ctx.modifiers, Some(ctx.name.clone())) .execute_on_remote(self.target.clone()) .privileged(&self.privilege_escalation_command) .keep_stdin_open()