mecha10_cli/dev/
types.rs

1//! Domain types for development mode
2
3use std::collections::HashMap;
4
5/// Development environment configuration
6#[allow(dead_code)] // Tested, planned for future use
7#[derive(Debug, Clone, PartialEq, Eq, Default)]
8pub enum DevEnvironment {
9    /// Local development
10    #[default]
11    Dev,
12    /// Staging environment
13    Staging,
14    /// Production environment
15    Production,
16    /// Custom environment
17    Custom(String),
18}
19
20#[allow(dead_code)] // Tested, planned for future use
21impl DevEnvironment {
22    /// Parse from string
23    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    /// Get string representation
33    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    /// Get display name
43    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/// Development mode configuration
54#[allow(dead_code)] // Tested, planned for future use
55#[derive(Debug, Clone)]
56pub struct DevConfig {
57    /// Environment name
58    pub environment: DevEnvironment,
59    /// Enable hot reload/watch mode
60    pub watch: bool,
61    /// Skip initial build
62    pub no_build: bool,
63    /// Specific nodes to run (empty = all enabled nodes)
64    pub nodes: Vec<String>,
65    /// Auto-start services
66    pub auto_start_services: bool,
67    /// Flush Redis on start
68    pub flush_redis: bool,
69    /// Additional environment variables
70    pub env_vars: HashMap<String, String>,
71}
72
73#[allow(dead_code)] // Tested, planned for future use
74impl DevConfig {
75    /// Create a new dev config with defaults
76    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    /// Set watch mode
89    pub fn with_watch(mut self, enabled: bool) -> Self {
90        self.watch = enabled;
91        self
92    }
93
94    /// Set no-build flag
95    pub fn with_no_build(mut self, enabled: bool) -> Self {
96        self.no_build = enabled;
97        self
98    }
99
100    /// Set specific nodes to run
101    pub fn with_nodes(mut self, nodes: Vec<String>) -> Self {
102        self.nodes = nodes;
103        self
104    }
105
106    /// Add a single node
107    pub fn with_node(mut self, node: impl Into<String>) -> Self {
108        self.nodes.push(node.into());
109        self
110    }
111
112    /// Set auto-start services
113    pub fn with_auto_start_services(mut self, enabled: bool) -> Self {
114        self.auto_start_services = enabled;
115        self
116    }
117
118    /// Set flush Redis
119    pub fn with_flush_redis(mut self, enabled: bool) -> Self {
120        self.flush_redis = enabled;
121        self
122    }
123
124    /// Add environment variable
125    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    /// Add multiple environment variables
131    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}