From 0aeea2ace7d9d9780e29b0807df921359eccc28c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Misty=20De=20M=C3=A9o?= Date: Tue, 27 Feb 2024 16:55:43 +1100 Subject: [PATCH] feat: add support for exec() --- src/lib.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index e2bdb1b..86733ca 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -68,6 +68,8 @@ //! Which is, a lot nicer! pub use error::*; +#[cfg(unix)] +use std::os::unix::process::CommandExt; use std::{ ffi::OsStr, path::Path, @@ -168,6 +170,7 @@ impl Cmd { self.status()?; Ok(()) } + /// Equivalent to [`std::process::Command::spawn`][], /// but logged and with the error wrapped. pub fn spawn(&mut self) -> Result { @@ -213,6 +216,19 @@ impl Cmd { self.status_inner() } + #[cfg(unix)] + /// Equivalent to [`std::process::Command::exec`][] + /// but logged, with the error wrapped + /// Note that, like the original, this will never return on success + pub fn exec(&mut self) -> Result { + self.log_command(); + let cause = self.inner.exec(); + Err(AxoprocessError::Exec { + summary: self.summary.clone(), + cause, + }) + } + /// Actual impl of status, split out to support a polyfill fn status_inner(&mut self) -> Result { self.log_command();