|
@@ -10,35 +10,28 @@ use tauri_utils::platform;
|
|
|
|
|
|
#[cfg(not(windows))]
|
|
|
pub fn get_output(cmd: String, args: Vec<String>, stdout: Stdio) -> crate::Result<String> {
|
|
|
- Command::new(cmd)
|
|
|
- .args(args)
|
|
|
- .stdout(stdout)
|
|
|
- .output()
|
|
|
- .map_err(|err| crate::Error::with_chain(err, "Command: get output failed"))
|
|
|
- .and_then(|output| {
|
|
|
- if output.status.success() {
|
|
|
- Ok(String::from_utf8_lossy(&output.stdout).to_string())
|
|
|
- } else {
|
|
|
- Err(crate::ErrorKind::Command(String::from_utf8_lossy(&output.stderr).to_string()).into())
|
|
|
- }
|
|
|
- })
|
|
|
+ let output = Command::new(cmd).args(args).stdout(stdout).output()?;
|
|
|
+
|
|
|
+ if output.status.success() {
|
|
|
+ Ok(String::from_utf8_lossy(&output.stdout).to_string())
|
|
|
+ } else {
|
|
|
+ Err(crate::Error::Command(String::from_utf8_lossy(&output.stderr).to_string()).into())
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
#[cfg(windows)]
|
|
|
pub fn get_output(cmd: String, args: Vec<String>, stdout: Stdio) -> crate::Result<String> {
|
|
|
- Command::new(cmd)
|
|
|
+ let output = Command::new(cmd)
|
|
|
.args(args)
|
|
|
.stdout(stdout)
|
|
|
.creation_flags(CREATE_NO_WINDOW)
|
|
|
- .output()
|
|
|
- .map_err(|err| crate::Error::with_chain(err, "Command: get output failed"))
|
|
|
- .and_then(|output| {
|
|
|
- if output.status.success() {
|
|
|
- Ok(String::from_utf8_lossy(&output.stdout).to_string())
|
|
|
- } else {
|
|
|
- Err(crate::ErrorKind::Command(String::from_utf8_lossy(&output.stderr).to_string()).into())
|
|
|
- }
|
|
|
- })
|
|
|
+ .output()?;
|
|
|
+
|
|
|
+ if output.status.success() {
|
|
|
+ Ok(String::from_utf8_lossy(&output.stdout).to_string())
|
|
|
+ } else {
|
|
|
+ Err(crate::Error::Command(String::from_utf8_lossy(&output.stderr).to_string()).into())
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
pub fn format_command(path: String, command: String) -> String {
|
|
@@ -52,7 +45,7 @@ pub fn format_command(path: String, command: String) -> String {
|
|
|
pub fn relative_command(command: String) -> crate::Result<String> {
|
|
|
match std::env::current_exe()?.parent() {
|
|
|
Some(exe_dir) => Ok(format_command(exe_dir.display().to_string(), command)),
|
|
|
- None => Err(crate::ErrorKind::Command("Could not evaluate executable dir".to_string()).into()),
|
|
|
+ None => Err(crate::Error::Command("Could not evaluate executable dir".to_string()).into()),
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -60,7 +53,7 @@ pub fn relative_command(command: String) -> crate::Result<String> {
|
|
|
pub fn command_path(command: String) -> crate::Result<String> {
|
|
|
match std::env::current_exe()?.parent() {
|
|
|
Some(exe_dir) => Ok(format!("{}/{}", exe_dir.display().to_string(), command)),
|
|
|
- None => Err(crate::ErrorKind::Command("Could not evaluate executable dir".to_string()).into()),
|
|
|
+ None => Err(crate::Error::Command("Could not evaluate executable dir".to_string()).into()),
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -68,7 +61,7 @@ pub fn command_path(command: String) -> crate::Result<String> {
|
|
|
pub fn command_path(command: String) -> crate::Result<String> {
|
|
|
match std::env::current_exe()?.parent() {
|
|
|
Some(exe_dir) => Ok(format!("{}/{}.exe", exe_dir.display().to_string(), command)),
|
|
|
- None => Err(crate::ErrorKind::Command("Could not evaluate executable dir".to_string()).into()),
|
|
|
+ None => Err(crate::Error::Command("Could not evaluate executable dir".to_string()).into()),
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -106,7 +99,8 @@ pub fn binary_command(binary_name: String) -> crate::Result<String> {
|
|
|
#[cfg(test)]
|
|
|
mod test {
|
|
|
use super::*;
|
|
|
- use crate::{Error, ErrorKind};
|
|
|
+ use crate::Error;
|
|
|
+ use std::io;
|
|
|
use totems::{assert_err, assert_ok};
|
|
|
|
|
|
#[test]
|
|
@@ -141,7 +135,7 @@ mod test {
|
|
|
assert_err!(&res);
|
|
|
|
|
|
// destruct the Error to check the ErrorKind and test that it is a Command type.
|
|
|
- if let Err(Error(ErrorKind::Command(e), _)) = &res {
|
|
|
+ if let Some(Error::Command(e)) = res.unwrap_err().downcast_ref::<Error>() {
|
|
|
// assert that the message in the error matches this string.
|
|
|
assert_eq!(*e, "cat: test/: Is a directory\n".to_string());
|
|
|
}
|
|
@@ -200,7 +194,7 @@ mod test {
|
|
|
assert_err!(&res);
|
|
|
|
|
|
// after asserting that the result is an error, check that the error kind is ErrorKind::Io
|
|
|
- if let Err(Error(ErrorKind::Io(s), _)) = &res {
|
|
|
+ if let Some(s) = res.unwrap_err().downcast_ref::<io::Error>() {
|
|
|
// assert that the ErrorKind inside of the ErrorKind Io is ErrorKind::NotFound
|
|
|
assert_eq!(s.kind(), std::io::ErrorKind::NotFound);
|
|
|
}
|