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 working_dir: Option<PathBuf>,
12 pub overrides: CliOverridesPatch,
14}
15
16impl ExecServerRequest {
17 pub fn new() -> Self {
18 Self {
19 listen: None,
20 working_dir: None,
21 overrides: CliOverridesPatch::default(),
22 }
23 }
24
25 pub fn listen(mut self, listen: impl Into<String>) -> Self {
27 let listen = listen.into();
28 self.listen = (!listen.trim().is_empty()).then_some(listen);
29 self
30 }
31
32 pub fn working_dir(mut self, dir: impl Into<PathBuf>) -> Self {
34 self.working_dir = Some(dir.into());
35 self
36 }
37
38 pub fn with_overrides(mut self, overrides: CliOverridesPatch) -> Self {
40 self.overrides = overrides;
41 self
42 }
43
44 pub fn config_override(mut self, key: impl Into<String>, value: impl Into<String>) -> Self {
46 self.overrides
47 .config_overrides
48 .push(ConfigOverride::new(key, value));
49 self
50 }
51
52 pub fn config_override_raw(mut self, raw: impl Into<String>) -> Self {
54 self.overrides
55 .config_overrides
56 .push(ConfigOverride::from_raw(raw));
57 self
58 }
59
60 pub fn profile(mut self, profile: impl Into<String>) -> Self {
62 let profile = profile.into();
63 self.overrides.profile = (!profile.trim().is_empty()).then_some(profile);
64 self
65 }
66
67 pub fn oss(mut self, enable: bool) -> Self {
69 self.overrides.oss = if enable {
70 FlagState::Enable
71 } else {
72 FlagState::Disable
73 };
74 self
75 }
76
77 pub fn enable_feature(mut self, name: impl Into<String>) -> Self {
79 self.overrides.feature_toggles.enable.push(name.into());
80 self
81 }
82
83 pub fn disable_feature(mut self, name: impl Into<String>) -> Self {
85 self.overrides.feature_toggles.disable.push(name.into());
86 self
87 }
88
89 pub fn search(mut self, enable: bool) -> Self {
91 self.overrides.search = if enable {
92 FlagState::Enable
93 } else {
94 FlagState::Disable
95 };
96 self
97 }
98}
99
100impl Default for ExecServerRequest {
101 fn default() -> Self {
102 Self::new()
103 }
104}