diff --git a/src/haiku.rs b/src/haiku.rs index 28c85aa..4f7a599 100644 --- a/src/haiku.rs +++ b/src/haiku.rs @@ -9,12 +9,13 @@ pub fn commands>(path: T) -> Vec { } pub fn that>(path: T) -> io::Result<()> { - commands(path)[0].status_without_output().into_result() + let cmd = &mut commands(path)[0]; + cmd.status_without_output().into_result(cmd) } pub fn with>(path: T, app: impl Into) -> io::Result<()> { - Command::new(app.into()) - .arg(path.as_ref()) + let mut cmd = Command::new(app.into()); + cmd.arg(path.as_ref()) .status_without_output() - .into_result() + .into_result(&cmd) } diff --git a/src/ios.rs b/src/ios.rs index 2a35ea6..ce1f8ef 100644 --- a/src/ios.rs +++ b/src/ios.rs @@ -9,15 +9,16 @@ pub fn commands>(path: T) -> Vec { } pub fn that>(path: T) -> io::Result<()> { - commands(path)[0].status_without_output().into_result() + let cmd = &mut commands(path)[0]; + cmd.status_without_output().into_result(cmd) } pub fn with>(path: T, app: impl Into) -> io::Result<()> { - Command::new("uiopen") - .arg("--url") + let mut cmd = Command::new("uiopen"); + cmd.arg("--url") .arg(path.as_ref()) .arg("--bundleid") .arg(app.into()) .status_without_output() - .into_result() + .into_result(&cmd) } diff --git a/src/lib.rs b/src/lib.rs index bdf58fb..3255bf4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -182,32 +182,22 @@ pub fn with_in_background>( } trait IntoResult { - fn into_result(self) -> T; + fn into_result(self, cmd: &Command) -> T; } impl IntoResult> for io::Result { - fn into_result(self) -> io::Result<()> { + fn into_result(self, cmd: &Command) -> io::Result<()> { match self { Ok(status) if status.success() => Ok(()), Ok(status) => Err(io::Error::new( io::ErrorKind::Other, - format!("Launcher failed with {:?}", status), + format!("Launcher {cmd:?} failed with {:?}", status), )), Err(err) => Err(err), } } } -#[cfg(windows)] -impl IntoResult> for std::os::raw::c_int { - fn into_result(self) -> io::Result<()> { - match self { - i if i > 32 => Ok(()), - _ => Err(io::Error::last_os_error()), - } - } -} - trait CommandExt { fn status_without_output(&mut self) -> io::Result; } diff --git a/src/macos.rs b/src/macos.rs index 7745389..000416c 100644 --- a/src/macos.rs +++ b/src/macos.rs @@ -9,14 +9,15 @@ pub fn commands>(path: T) -> Vec { } pub fn that>(path: T) -> io::Result<()> { - commands(path)[0].status_without_output().into_result() + let cmd = &mut commands(path)[0]; + cmd.status_without_output().into_result(cmd) } pub fn with>(path: T, app: impl Into) -> io::Result<()> { - Command::new("/usr/bin/open") - .arg(path.as_ref()) + let mut cmd = Command::new("/usr/bin/open"); + cmd.arg(path.as_ref()) .arg("-a") .arg(app.into()) .status_without_output() - .into_result() + .into_result(&cmd) } diff --git a/src/unix.rs b/src/unix.rs index d1b4175..bfd9f84 100644 --- a/src/unix.rs +++ b/src/unix.rs @@ -28,10 +28,10 @@ pub fn commands>(path: T) -> Vec { pub fn that>(path: T) -> io::Result<()> { let mut last_err = None; - for mut command in commands(path) { - match command.status_without_output() { + for mut cmd in commands(path) { + match cmd.status_without_output() { Ok(status) => { - return Ok(status).into_result(); + return Ok(status).into_result(&cmd); } Err(err) => last_err = Some(err), } @@ -40,10 +40,10 @@ pub fn that>(path: T) -> io::Result<()> { } pub fn with>(path: T, app: impl Into) -> io::Result<()> { - Command::new(app.into()) - .arg(path.as_ref()) + let mut cmd = Command::new(app.into()); + cmd.arg(path.as_ref()) .status_without_output() - .into_result() + .into_result(&cmd) } // Polyfill to workaround absolute path bug in wslu(wslview). In versions before diff --git a/src/windows.rs b/src/windows.rs index 28a2294..bf3dc15 100644 --- a/src/windows.rs +++ b/src/windows.rs @@ -9,14 +9,15 @@ pub fn commands>(path: T) -> Vec { } pub fn that>(path: T) -> io::Result<()> { - commands(path)[0].status_without_output().into_result() + let cmd = &mut commands(path)[0]; + cmd.status_without_output().into_result(cmd) } pub fn with>(path: T, app: impl Into) -> io::Result<()> { - Command::new("cmd") - .arg("/c") + let mut cmd = Command::new("cmd"); + cmd.arg("/c") .arg(app.into()) .arg(path.as_ref()) .status_without_output() - .into_result() + .into_result(&cmd) }