Skip to content

Commit

Permalink
feat: add support for exec()
Browse files Browse the repository at this point in the history
  • Loading branch information
mistydemeo committed Dec 12, 2024
1 parent 0a87650 commit 0aeea2a
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<std::process::Child> {
Expand Down Expand Up @@ -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<ExitStatus> {
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<ExitStatus> {
self.log_command();
Expand Down

0 comments on commit 0aeea2a

Please sign in to comment.