use std::collections::{BTreeMap, HashMap};
use std::path::PathBuf;
use std::time::Duration;
use tokio_util::sync::CancellationToken;
use crate::value::Value;
#[derive(Default, Clone)]
pub struct ExecuteOptions {
pub vars: HashMap<String, Value>,
pub timeout: Option<Duration>,
pub cancel_token: Option<CancellationToken>,
pub cwd: Option<PathBuf>,
pub traceparent: Option<String>,
pub tracestate: Option<String>,
pub baggage: BTreeMap<String, String>,
}
impl ExecuteOptions {
pub fn new() -> Self {
Self::default()
}
pub fn with_vars(mut self, vars: HashMap<String, Value>) -> Self {
self.vars = vars;
self
}
pub fn with_var(mut self, name: impl Into<String>, value: Value) -> Self {
self.vars.insert(name.into(), value);
self
}
pub fn with_timeout(mut self, timeout: Duration) -> Self {
self.timeout = Some(timeout);
self
}
pub fn with_cancel_token(mut self, token: CancellationToken) -> Self {
self.cancel_token = Some(token);
self
}
pub fn with_cwd(mut self, cwd: PathBuf) -> Self {
self.cwd = Some(cwd);
self
}
pub fn with_traceparent(mut self, traceparent: impl Into<String>) -> Self {
self.traceparent = Some(traceparent.into());
self
}
pub fn with_tracestate(mut self, tracestate: impl Into<String>) -> Self {
self.tracestate = Some(tracestate.into());
self
}
pub fn with_baggage(mut self, baggage: BTreeMap<String, String>) -> Self {
self.baggage = baggage;
self
}
pub fn with_baggage_entry(mut self, key: impl Into<String>, value: impl Into<String>) -> Self {
self.baggage.insert(key.into(), value.into());
self
}
}