refactor: refactor

This commit is contained in:
graelo 2020-05-27 10:04:42 +02:00
parent 623c66cbba
commit 791aaadd49
10 changed files with 655 additions and 468 deletions

21
src/process.rs Normal file
View file

@ -0,0 +1,21 @@
use std::process::Command;
use crate::error::ParseError;
/// Execute an arbitrary Unix command and return the stdout as a `String` if
/// successful.
pub fn execute(command: &str, args: &Vec<&str>) -> Result<String, ParseError> {
let output = Command::new(command).args(args).output()?;
if !output.status.success() {
let msg = String::from_utf8_lossy(&output.stderr);
return Err(ParseError::ProcessFailure(format!(
"Process failure: {} {}, error {}",
command,
args.join(" "),
msg
)));
}
Ok(String::from_utf8_lossy(&output.stdout).to_string())
}