From 622a58db5a06b1c4b29d9036ffaa593edff771b2 Mon Sep 17 00:00:00 2001 From: datdenkikniet Date: Sat, 15 Apr 2023 13:55:56 +0200 Subject: [PATCH] Also log command with enough verbosity --- xtask/src/command.rs | 19 +++++++++++++++---- xtask/src/main.rs | 2 +- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/xtask/src/command.rs b/xtask/src/command.rs index 71dda2b83b..d05a95b35f 100644 --- a/xtask/src/command.rs +++ b/xtask/src/command.rs @@ -1,7 +1,8 @@ use log::{error, info, Level}; use crate::{ - cargo_commands::FinalRunResult, ExtraArguments, Package, RunResult, Target, TestRunError, + argument_parsing::Globals, cargo_commands::FinalRunResult, ExtraArguments, Package, RunResult, + Target, TestRunError, }; use core::fmt; use std::{ @@ -305,6 +306,12 @@ impl core::fmt::Display for CargoCommand<'_> { } impl<'a> CargoCommand<'a> { + pub fn as_cmd_string(&self) -> String { + let executable = self.executable(); + let args = self.args().join(" "); + format!("{executable} {args}") + } + fn command(&self) -> &str { match self { CargoCommand::Run { .. } | CargoCommand::Qemu { .. } => "run", @@ -702,7 +709,7 @@ pub fn run_successful(run: &RunResult, expected_output_file: &str) -> Result<(), } } -pub fn handle_results(results: Vec) -> anyhow::Result<()> { +pub fn handle_results(globals: &Globals, results: Vec) -> anyhow::Result<()> { let errors = results.iter().filter_map(|r| { if let FinalRunResult::Failed(c, r) = r { Some((c, r)) @@ -748,11 +755,15 @@ pub fn handle_results(results: Vec) -> anyhow::Result<()> { errors.clone().for_each(log_stdout_stderr(Level::Error)); successes.for_each(|(cmd, _)| { - info!("✅ Success: {cmd}"); + if globals.verbose > 0 { + info!("✅ Success: {cmd}\n {}", cmd.as_cmd_string()); + } else { + info!("✅ Success: {cmd}"); + } }); errors.clone().for_each(|(cmd, _)| { - error!("❌ Failed: {cmd}"); + error!("❌ Failed: {cmd}\n {}", cmd.as_cmd_string()); }); let ecount = errors.count(); diff --git a/xtask/src/main.rs b/xtask/src/main.rs index b572591fd4..eab21b3291 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -287,7 +287,7 @@ fn main() -> anyhow::Result<()> { } }; - handle_results(final_run_results) + handle_results(globals, final_run_results) } // run example binary `example`