use std::path::PathBuf;
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct Launch {
pub program: PathBuf,
pub args: Vec<String>,
pub env: Vec<(String, String)>,
pub cwd: Option<PathBuf>,
}
impl Launch {
pub fn new(program: impl Into<PathBuf>) -> Self {
Self {
program: program.into(),
..Self::default()
}
}
#[must_use]
pub fn args<I, S>(mut self, args: I) -> Self
where
I: IntoIterator<Item = S>,
S: Into<String>,
{
self.args.extend(args.into_iter().map(Into::into));
self
}
#[must_use]
pub fn env(mut self, name: impl Into<String>, value: impl Into<String>) -> Self {
let name = name.into();
self.env.retain(|(set, _)| *set != name);
self.env.push((name, value.into()));
self
}
#[must_use]
pub fn cwd(mut self, cwd: impl Into<PathBuf>) -> Self {
self.cwd = Some(cwd.into());
self
}
}