use std::ffi::{OsStr, OsString};
use std::io;
use std::process::ExitStatus;
use crate::runas::runas_root;
pub struct Command {
pub(crate) command: OsString,
pub(crate) args: Vec<OsString>,
pub(crate) force_prompt: bool,
pub(crate) hide: bool,
pub(crate) gui: bool,
}
impl Command {
pub fn new<S: AsRef<OsStr>>(program: S) -> Command {
Command {
command: program.as_ref().to_os_string(),
args: vec![],
hide: false,
gui: false,
force_prompt: true,
}
}
pub fn arg<S: AsRef<OsStr>>(&mut self, arg: S) -> &mut Command {
self.args.push(arg.as_ref().to_os_string());
self
}
pub fn args<S: AsRef<OsStr>>(&mut self, args: &[S]) -> &mut Command {
for arg in args {
self.arg(arg);
}
self
}
pub fn hide(&mut self, val: bool) -> &mut Command {
self.hide = val;
self
}
pub fn gui(&mut self, val: bool) -> &mut Command {
self.gui = val;
self
}
pub fn force_prompt(&mut self, val: bool) -> &mut Command {
self.force_prompt = val;
self
}
pub fn run(&mut self) -> io::Result<ExitStatus> {
runas_root(self)
}
}