1use std::collections::HashMap;
4
5#[allow(dead_code)]
7#[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)]
21impl 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 {
41 match self {
42 Self::Dev => "dev",
43 Self::Staging => "staging",
44 Self::Production => "production",
45 Self::Custom(s) => s.as_str(),
46 }
47 }
48
49 pub fn display_name(&self) -> String {
51 match self {
52 Self::Dev => "Development".to_string(),
53 Self::Staging => "Staging".to_string(),
54 Self::Production => "Production".to_string(),
55 Self::Custom(s) => s.clone(),
56 }
57 }
58}
59
60#[allow(dead_code)]
62#[derive(Debug, Clone)]
63pub struct DevConfig {
64 pub environment: DevEnvironment,
66 pub watch: bool,
68 pub no_build: bool,
70 pub nodes: Vec<String>,
72 pub auto_start_services: bool,
74 pub flush_redis: bool,
76 pub env_vars: HashMap<String, String>,
78}
79
80#[allow(dead_code)]
81impl DevConfig {
82 pub fn new(environment: DevEnvironment) -> Self {
84 Self {
85 environment,
86 watch: false,
87 no_build: false,
88 nodes: Vec::new(),
89 auto_start_services: true,
90 flush_redis: true,
91 env_vars: HashMap::new(),
92 }
93 }
94
95 pub fn with_watch(mut self, enabled: bool) -> Self {
97 self.watch = enabled;
98 self
99 }
100
101 pub fn with_no_build(mut self, enabled: bool) -> Self {
103 self.no_build = enabled;
104 self
105 }
106
107 pub fn with_nodes(mut self, nodes: Vec<String>) -> Self {
109 self.nodes = nodes;
110 self
111 }
112
113 mecha10_core::builder_setter!(
114 push, with_node, nodes, impl Into<String>
116 );
117
118 pub fn with_auto_start_services(mut self, enabled: bool) -> Self {
120 self.auto_start_services = enabled;
121 self
122 }
123
124 pub fn with_flush_redis(mut self, enabled: bool) -> Self {
126 self.flush_redis = enabled;
127 self
128 }
129
130 mecha10_core::builder_setter!(
131 insert, with_env_var, env_vars, impl Into<String>, impl Into<String>
133 );
134}
135
136impl Default for DevConfig {
137 fn default() -> Self {
138 Self::new(DevEnvironment::default())
139 }
140}