feat: hand back the command's exit code
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
use anyhow::{Context, Result, bail};
|
||||
use std::{
|
||||
fmt::Display,
|
||||
os::unix::process::CommandExt,
|
||||
process::{Child, Command, ExitStatus, Stdio},
|
||||
sync::OnceLock,
|
||||
};
|
||||
@@ -83,6 +84,19 @@ impl CommandBuilder {
|
||||
check(&shown, status)
|
||||
}
|
||||
|
||||
// replaces this process, so the command's exit code and signals become ours
|
||||
pub fn exec_replace(self) -> Result<()> {
|
||||
if options().dry_run {
|
||||
eprintln!("would run `{self}`");
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let shown = self.to_string();
|
||||
let error = self.build()?.exec();
|
||||
|
||||
Err(error).with_context(|| format!("running `{shown}`"))
|
||||
}
|
||||
|
||||
pub fn spawn(self) -> Result<Child> {
|
||||
Ok(self.build()?.spawn()?)
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ pub fn run(service: &str, rest: &[String]) -> Result<()> {
|
||||
.args("run --rm")
|
||||
.arg(service)
|
||||
.args(rest)
|
||||
.exec()
|
||||
.exec_replace()
|
||||
}
|
||||
|
||||
pub fn exec(service: &str, rest: &[String]) -> Result<()> {
|
||||
|
||||
Reference in New Issue
Block a user