use std::ffi::OsString;
use std::process::Command;
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct ProgramArgs {
program: OsString,
args: Vec<OsString>,
}
impl ProgramArgs {
#[inline]
pub fn new<S: Into<OsString>>(program: S) -> ProgramArgs {
ProgramArgs {
program: program.into(),
args: Vec::new(),
}
}
#[inline]
pub fn push<S: Into<OsString>>(&mut self, arg: S) {
self.args.push(arg.into());
}
pub fn into_command(self) -> Command {
let mut cmd = Command::new(&self.program);
cmd.args(&self.args);
cmd
}
}
impl<S: Into<OsString>> Extend<S> for ProgramArgs {
fn extend<T: IntoIterator<Item = S>>(&mut self, iterable: T) {
self.args.extend(iterable.into_iter().map(Into::into));
}
}