use std::collections::BTreeMap;
use std::path::PathBuf;
#[derive(Clone, Debug, PartialEq, Eq)]
pub(crate) struct TaskProgram {
pub(crate) name: String,
pub(crate) script_path: PathBuf,
pub(crate) args: Vec<String>,
pub(crate) cwd: Option<PathBuf>,
pub(crate) environment: BTreeMap<String, String>,
#[cfg(feature = "tasks")]
pub(crate) log: claviron_tasks::LogConfig,
pub(crate) execution_timeout: Option<std::time::Duration>,
}
impl TaskProgram {
pub fn new(
name: impl Into<String>,
script_path: impl Into<PathBuf>,
) -> Self {
Self {
name: name.into(),
script_path: script_path.into(),
args: Vec::new(),
cwd: None,
environment: BTreeMap::new(),
#[cfg(feature = "tasks")]
log: claviron_tasks::LogConfig::default(),
execution_timeout: None,
}
}
pub fn args(
mut self,
args: impl IntoIterator<Item = impl Into<String>>,
) -> Self {
self.args.extend(args.into_iter().map(Into::into));
self
}
pub fn cwd(
mut self,
cwd: impl Into<PathBuf>,
) -> Self {
self.cwd = Some(cwd.into());
self
}
pub fn execution_timeout(
mut self,
budget: Option<std::time::Duration>,
) -> Self {
self.execution_timeout = budget;
self
}
pub fn environment(
mut self,
key: impl Into<String>,
value: impl Into<String>,
) -> Self {
self.environment.insert(key.into(), value.into());
self
}
#[cfg(feature = "tasks")]
pub fn log(
mut self,
log: claviron_tasks::LogConfig,
) -> Self {
self.log = log;
self
}
}