feat: hand back the command's exit code

This commit is contained in:
2026-09-08 09:53:38 +00:00
parent 3fa4739451
commit aec7afb274
2 changed files with 15 additions and 1 deletions

View File

@@ -1,6 +1,7 @@
use anyhow::{Context, Result, bail}; use anyhow::{Context, Result, bail};
use std::{ use std::{
fmt::Display, fmt::Display,
os::unix::process::CommandExt,
process::{Child, Command, ExitStatus, Stdio}, process::{Child, Command, ExitStatus, Stdio},
sync::OnceLock, sync::OnceLock,
}; };
@@ -83,6 +84,19 @@ impl CommandBuilder {
check(&shown, status) 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> { pub fn spawn(self) -> Result<Child> {
Ok(self.build()?.spawn()?) Ok(self.build()?.spawn()?)
} }

View File

@@ -15,7 +15,7 @@ pub fn run(service: &str, rest: &[String]) -> Result<()> {
.args("run --rm") .args("run --rm")
.arg(service) .arg(service)
.args(rest) .args(rest)
.exec() .exec_replace()
} }
pub fn exec(service: &str, rest: &[String]) -> Result<()> { pub fn exec(service: &str, rest: &[String]) -> Result<()> {