1use std::collections::HashMap;
4
5#[allow(dead_code)] #[derive(Debug, Clone, PartialEq, Eq, Default)]
8pub enum DevEnvironment {
9 #[default]
11 Dev,
12 Staging,
14 Production,
16 Custom(String),
18}
19
20#[allow(dead_code)] impl DevEnvironment {
22 pub fn parse_environment(s: &str) -> Self {
24 match s.to_lowercase().as_str() {
25 "dev" | "development" => Self::Dev,
26 "staging" | "stage" => Self::Staging,
27 "production" | "prod" => Self::Production,
28 _ => Self::Custom(s.to_string()),
29 }
30 }
31
32 pub fn as_str(&self) -> &str {
34 match self {
35 Self::Dev => "dev",
36 Self::Staging => "staging",
37 Self::Production => "production",
38 Self::Custom(s) => s.as_str(),
39 }
40 }
41
42 pub fn display_name(&self) -> String {
44 match self {
45 Self::Dev => "Development".to_string(),
46 Self::Staging => "Staging".to_string(),
47 Self::Production => "Production".to_string(),
48 Self::Custom(s) => s.clone(),
49 }
50 }
51}
52
53#[allow(dead_code)] #[derive(Debug, Clone)]
56pub struct DevConfig {
57 pub environment: DevEnvironment,
59 pub watch: bool,
61 pub no_build: bool,
63 pub nodes: Vec<String>,
65 pub auto_start_services: bool,
67 pub flush_redis: bool,
69 pub env_vars: HashMap<String, String>,
71}
72
73#[allow(dead_code)] impl DevConfig {
75 pub fn new(environment: DevEnvironment) -> Self {
77 Self {
78 environment,
79 watch: false,
80 no_build: false,
81 nodes: Vec::new(),
82 auto_start_services: true,
83 flush_redis: true,
84 env_vars: HashMap::new(),
85 }
86 }
87
88 pub fn with_watch(mut self, enabled: bool) -> Self {
90 self.watch = enabled;
91 self
92 }
93
94 pub fn with_no_build(mut self, enabled: bool) -> Self {
96 self.no_build = enabled;
97 self
98 }
99
100 pub fn with_nodes(mut self, nodes: Vec<String>) -> Self {
102 self.nodes = nodes;
103 self
104 }
105
106 pub fn with_node(mut self, node: impl Into<String>) -> Self {
108 self.nodes.push(node.into());
109 self
110 }
111
112 pub fn with_auto_start_services(mut self, enabled: bool) -> Self {
114 self.auto_start_services = enabled;
115 self
116 }
117
118 pub fn with_flush_redis(mut self, enabled: bool) -> Self {
120 self.flush_redis = enabled;
121 self
122 }
123
124 pub fn with_env_var(mut self, key: impl Into<String>, value: impl Into<String>) -> Self {
126 self.env_vars.insert(key.into(), value.into());
127 self
128 }
129
130 pub fn with_env_vars(mut self, vars: HashMap<String, String>) -> Self {
132 self.env_vars.extend(vars);
133 self
134 }
135}
136
137impl Default for DevConfig {
138 fn default() -> Self {
139 Self::new(DevEnvironment::default())
140 }
141}