1use std::collections::HashMap;
4
5#[allow(dead_code)]
6#[derive(Debug, Clone, PartialEq, Eq, Default)]
7pub enum DevEnvironment {
8 #[default]
9 Dev,
10 Staging,
11 Production,
12 Custom(String),
13}
14
15#[allow(dead_code)]
16impl DevEnvironment {
17 pub fn parse_environment(s: &str) -> Self {
19 match s.to_lowercase().as_str() {
20 "dev" | "development" => Self::Dev,
21 "staging" | "stage" => Self::Staging,
22 "production" | "prod" => Self::Production,
23 _ => Self::Custom(s.to_string()),
24 }
25 }
26
27 pub fn as_str(&self) -> &str {
29 match self {
30 Self::Dev => "dev",
31 Self::Staging => "staging",
32 Self::Production => "production",
33 Self::Custom(s) => s.as_str(),
34 }
35 }
36
37 pub fn display_name(&self) -> String {
39 match self {
40 Self::Dev => "Development".to_string(),
41 Self::Staging => "Staging".to_string(),
42 Self::Production => "Production".to_string(),
43 Self::Custom(s) => s.clone(),
44 }
45 }
46}
47
48#[allow(dead_code)]
49#[derive(Debug, Clone)]
50pub struct DevConfig {
51 pub environment: DevEnvironment,
52 pub watch: bool,
53 pub no_build: bool,
54 pub nodes: Vec<String>,
55 pub auto_start_services: bool,
56 pub flush_redis: bool,
57 pub env_vars: HashMap<String, String>,
58}
59
60#[allow(dead_code)]
61impl DevConfig {
62 pub fn new(environment: DevEnvironment) -> Self {
64 Self {
65 environment,
66 watch: false,
67 no_build: false,
68 nodes: Vec::new(),
69 auto_start_services: true,
70 flush_redis: true,
71 env_vars: HashMap::new(),
72 }
73 }
74
75 pub fn with_watch(mut self, enabled: bool) -> Self {
77 self.watch = enabled;
78 self
79 }
80
81 pub fn with_no_build(mut self, enabled: bool) -> Self {
83 self.no_build = enabled;
84 self
85 }
86
87 pub fn with_nodes(mut self, nodes: Vec<String>) -> Self {
89 self.nodes = nodes;
90 self
91 }
92
93 mecha10_core::builder_setter!(
94 push, with_node, nodes, impl Into<String>
96 );
97
98 pub fn with_auto_start_services(mut self, enabled: bool) -> Self {
100 self.auto_start_services = enabled;
101 self
102 }
103
104 pub fn with_flush_redis(mut self, enabled: bool) -> Self {
106 self.flush_redis = enabled;
107 self
108 }
109
110 mecha10_core::builder_setter!(
111 insert, with_env_var, env_vars, impl Into<String>, impl Into<String>
113 );
114}
115
116impl Default for DevConfig {
117 fn default() -> Self {
118 Self::new(DevEnvironment::default())
119 }
120}