use std::fmt::Display;
use std::process::Command;
use std::str::from_utf8;
#[derive(Clone, PartialEq, Debug)]
pub struct Cmd {
pub program: String,
pub args: Vec<String>,
}
impl Cmd {
pub fn new<S: Display>(program: S) -> Self {
Self {
program: program.to_string(),
args: vec![],
}
}
pub fn arg<S: Display>(mut self, s: S) -> Self {
self.args.push(s.to_string());
self
}
pub fn run(&self) -> String {
match Command::new(&self.program).args(&self.args).output() {
Ok(o) => match from_utf8(&o.stdout) {
Ok(s) => s.to_string(),
Err(_) => String::from(""),
},
Err(_) => String::from(""),
}
}
}