use std::path::PathBuf;
use crate::{CliOverridesPatch, ConfigOverride, FlagState};
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct ExecServerRequest {
pub listen: Option<String>,
pub working_dir: Option<PathBuf>,
pub overrides: CliOverridesPatch,
}
impl ExecServerRequest {
pub fn new() -> Self {
Self {
listen: None,
working_dir: None,
overrides: CliOverridesPatch::default(),
}
}
pub fn listen(mut self, listen: impl Into<String>) -> Self {
let listen = listen.into();
self.listen = (!listen.trim().is_empty()).then_some(listen);
self
}
pub fn working_dir(mut self, dir: impl Into<PathBuf>) -> Self {
self.working_dir = Some(dir.into());
self
}
pub fn with_overrides(mut self, overrides: CliOverridesPatch) -> Self {
self.overrides = overrides;
self
}
pub fn config_override(mut self, key: impl Into<String>, value: impl Into<String>) -> Self {
self.overrides
.config_overrides
.push(ConfigOverride::new(key, value));
self
}
pub fn config_override_raw(mut self, raw: impl Into<String>) -> Self {
self.overrides
.config_overrides
.push(ConfigOverride::from_raw(raw));
self
}
pub fn profile(mut self, profile: impl Into<String>) -> Self {
let profile = profile.into();
self.overrides.profile = (!profile.trim().is_empty()).then_some(profile);
self
}
pub fn oss(mut self, enable: bool) -> Self {
self.overrides.oss = if enable {
FlagState::Enable
} else {
FlagState::Disable
};
self
}
pub fn enable_feature(mut self, name: impl Into<String>) -> Self {
self.overrides.feature_toggles.enable.push(name.into());
self
}
pub fn disable_feature(mut self, name: impl Into<String>) -> Self {
self.overrides.feature_toggles.disable.push(name.into());
self
}
pub fn search(mut self, enable: bool) -> Self {
self.overrides.search = if enable {
FlagState::Enable
} else {
FlagState::Disable
};
self
}
}
impl Default for ExecServerRequest {
fn default() -> Self {
Self::new()
}
}