From: Ian Jackson Date: Sun, 8 Aug 2021 00:10:31 +0000 (+0100) Subject: ipif: Introduce OptionPrefixColon X-Git-Tag: hippotat/1.0.0~244 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=79b788a42277df4f0a8ba04d9de77cbebf1fe029;p=hippotat.git ipif: Introduce OptionPrefixColon Signed-off-by: Ian Jackson --- diff --git a/src/bin/client.rs b/src/bin/client.rs index 04d6cac..2f2e676 100644 --- a/src/bin/client.rs +++ b/src/bin/client.rs @@ -179,7 +179,7 @@ async fn run_client( ic: &ic, }; - let mut ipif = Ipif::start(&ic.ipif, ic.to_string())?; + let mut ipif = Ipif::start(&ic.ipif, Some(ic.to_string()))?; let mut req_num: ReqNum = 0; diff --git a/src/ipif.rs b/src/ipif.rs index 196b6b3..14f9d6d 100644 --- a/src/ipif.rs +++ b/src/ipif.rs @@ -13,7 +13,7 @@ pub struct Ipif { impl Ipif { #[throws(AE)] - pub fn start(cmd: &str, ic_name: String) -> Self { + pub fn start(cmd: &str, ic_name: Option) -> Self { let mut child = tokio::process::Command::new("sh") .args(&["-c", cmd]) .stdin (process::Stdio::piped()) @@ -27,7 +27,9 @@ impl Ipif { let stderr_task = task::spawn(async move { let mut stderr = t_io::BufReader::new(stderr).lines(); while let Some(l) = stderr.next_line().await? { - error!("{}: ipif stderr: {}", ic_name, l.trim_end()); + error!("{}ipif stderr: {}", + OptionPrefixColon(ic_name.as_ref()), + l.trim_end()); } Ok::<_,io::Error>(()) }); diff --git a/src/reporter.rs b/src/reporter.rs index 8a92b39..49b784b 100644 --- a/src/reporter.rs +++ b/src/reporter.rs @@ -31,6 +31,14 @@ impl LogOpts { } } +pub struct OptionPrefixColon(pub Option); +impl Display for OptionPrefixColon { + #[throws(fmt::Error)] + fn fmt(&self, f: &mut fmt::Formatter) { + if let Some(x) = &self.0 { write!(f, "{}: ", x)? } + } +} + // For clients only, really. pub struct Reporter<'r> { ic: &'r InstanceConfig,