1use std::path::PathBuf;
2
3use crate::{CliOverridesPatch, ConfigOverride, FlagState};
4
5#[derive(Clone, Debug, Eq, PartialEq)]
7pub struct ExecServerRequest {
8 pub listen: Option<String>,
10 pub executor_id: Option<String>,
12 pub name: Option<String>,
14 pub working_dir: Option<PathBuf>,
16 pub overrides: CliOverridesPatch,
18}
19
20impl ExecServerRequest {
21 pub fn new() -> Self {
22 Self {
23 listen: None,
24 executor_id: None,
25 name: None,
26 working_dir: None,
27 overrides: CliOverridesPatch::default(),
28 }
29 }
30
31 pub fn listen(mut self, listen: impl Into<String>) -> Self {
33 let listen = listen.into();
34 self.listen = (!listen.trim().is_empty()).then_some(listen);
35 self
36 }
37
38 pub fn executor_id(mut self, executor_id: impl Into<String>) -> Self {
40 let executor_id = executor_id.into();
41 self.executor_id = (!executor_id.trim().is_empty()).then_some(executor_id);
42 self
43 }
44
45 pub fn name(mut self, name: impl Into<String>) -> Self {
47 let name = name.into();
48 self.name = (!name.trim().is_empty()).then_some(name);
49 self
50 }
51
52 pub fn working_dir(mut self, dir: impl Into<PathBuf>) -> Self {
54 self.working_dir = Some(dir.into());
55 self
56 }
57
58 pub fn with_overrides(mut self, overrides: CliOverridesPatch) -> Self {
60 self.overrides = overrides;
61 self
62 }
63
64 pub fn config_override(mut self, key: impl Into<String>, value: impl Into<String>) -> Self {
66 self.overrides
67 .config_overrides
68 .push(ConfigOverride::new(key, value));
69 self
70 }
71
72 pub fn config_override_raw(mut self, raw: impl Into<String>) -> Self {
74 self.overrides
75 .config_overrides
76 .push(ConfigOverride::from_raw(raw));
77 self
78 }
79
80 pub fn profile(mut self, profile: impl Into<String>) -> Self {
82 let profile = profile.into();
83 self.overrides.profile = (!profile.trim().is_empty()).then_some(profile);
84 self
85 }
86
87 pub fn oss(mut self, enable: bool) -> Self {
89 self.overrides.oss = if enable {
90 FlagState::Enable
91 } else {
92 FlagState::Disable
93 };
94 self
95 }
96
97 pub fn enable_feature(mut self, name: impl Into<String>) -> Self {
99 self.overrides.feature_toggles.enable.push(name.into());
100 self
101 }
102
103 pub fn disable_feature(mut self, name: impl Into<String>) -> Self {
105 self.overrides.feature_toggles.disable.push(name.into());
106 self
107 }
108
109 pub fn search(mut self, enable: bool) -> Self {
111 self.overrides.search = if enable {
112 FlagState::Enable
113 } else {
114 FlagState::Disable
115 };
116 self
117 }
118}
119
120impl Default for ExecServerRequest {
121 fn default() -> Self {
122 Self::new()
123 }
124}