1 parent
46a86116b0
commit
286def05c1
7 files changed
+303
-50
No files matched your search
@@ -0,0 +1,27 @@
|
||||
use std::process::Command;
|
||||
|
||||
use anyhow::{Context, anyhow, bail};
|
||||
|
||||
pub fn cmd(cmd: &[&str]) -> anyhow::Result<String> {
|
||||
let [cmd, args @ ..] = cmd else {
|
||||
bail!("missing command");
|
||||
};
|
||||
|
||||
let mut command = Command::new(cmd);
|
||||
command.args(args);
|
||||
println!("$ {command:?}");
|
||||
let output = command
|
||||
.output()
|
||||
.with_context(|| anyhow!("Failed to run {command:?}"))?;
|
||||
|
||||
let stdout = String::from_utf8_lossy(&output.stdout);
|
||||
if !output.status.success() {
|
||||
let stderr = String::from_utf8_lossy(&output.stderr);
|
||||
eprintln!("{command:?} failed");
|
||||
eprintln!("stdout:\n{stdout}\n");
|
||||
eprintln!("stderr:\n{stderr}\n");
|
||||
bail!("{command:?} failed with exit code {}", output.status);
|
||||
}
|
||||
|
||||
Ok(stdout.to_string())
|
||||
}
|
||||
Reference in new issue
Block a user