anyhow_std/process/
command.rs1use crate::process::{Child, ExitStatus, Output};
2use anyhow::Context;
3use std::process::Command;
4
5pub trait CommandAnyhow {
7 fn spawn_anyhow(&mut self) -> anyhow::Result<Child>;
9
10 fn output_anyhow(&mut self) -> anyhow::Result<Output>;
12
13 fn status_anyhow(&mut self) -> anyhow::Result<ExitStatus>;
15
16 fn anyhow_context(&self) -> String;
18}
19
20impl CommandAnyhow for Command {
21 fn spawn_anyhow(&mut self) -> anyhow::Result<Child> {
22 self.spawn()
23 .map(|c| Child::from((c, self.anyhow_context())))
24 .context(self.anyhow_context())
25 }
26
27 fn output_anyhow(&mut self) -> anyhow::Result<Output> {
28 self.output()
29 .map(|o| Output::wrap(o, self.anyhow_context()))
30 .context(self.anyhow_context())
31 }
32
33 fn status_anyhow(&mut self) -> anyhow::Result<ExitStatus> {
34 self.status()
35 .map(|c| ExitStatus::from((c, self.anyhow_context())))
36 .context(self.anyhow_context())
37 }
38
39 fn anyhow_context(&self) -> String {
40 format!("command: {:?}", self)
41 }
42}