use std::ffi::OsString;
use std::path::{Path, PathBuf};
#[derive(Debug, Clone)]
pub(crate) struct ProcessSpec {
program: OsString,
arguments: Vec<OsString>,
directory: PathBuf,
environment: Vec<(OsString, OsString)>,
new_process_group: bool,
}
impl ProcessSpec {
pub(crate) fn new(program: impl Into<OsString>, directory: impl Into<PathBuf>) -> Self {
Self {
program: program.into(),
arguments: Vec::new(),
directory: directory.into(),
environment: Vec::new(),
new_process_group: false,
}
}
pub(crate) fn arg(mut self, value: impl Into<OsString>) -> Self {
self.arguments.push(value.into());
self
}
pub(crate) fn args<I, T>(mut self, values: I) -> Self
where
I: IntoIterator<Item = T>,
T: Into<OsString>,
{
self.arguments.extend(values.into_iter().map(Into::into));
self
}
pub(crate) fn env(mut self, key: impl Into<OsString>, value: impl Into<OsString>) -> Self {
self.environment.push((key.into(), value.into()));
self
}
pub(crate) fn new_process_group(mut self, enabled: bool) -> Self {
self.new_process_group = enabled;
self
}
pub(crate) fn program(&self) -> &std::ffi::OsStr {
&self.program
}
pub(crate) fn arguments(&self) -> &[OsString] {
&self.arguments
}
pub(crate) fn directory(&self) -> &Path {
&self.directory
}
pub(crate) fn environment(&self) -> &[(OsString, OsString)] {
&self.environment
}
#[cfg_attr(not(windows), allow(dead_code))]
pub(crate) fn new_process_group_enabled(&self) -> bool {
self.new_process_group
}
}