Skip to main content

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)]
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)]
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    // duplicate: false positive — matches `DriverType::as_str` (mecha10-templates) and
33    // `StartTarget::as_str` (launcher-service) on the match-per-variant-returning-&str AST
34    // shape, but `DevEnvironment` has a data-carrying `Custom(String)` variant that returns
35    // `s.as_str()` instead of a literal, so it doesn't fit the workspace's `enum_str_method!`
36    // macro (fieldless-variant, one-literal-per-arm shape only) those two otherwise share; no
37    // helper covers both shapes (see `.dupes-ignore.toml`'s matching entry for the pairwise
38    // `DriverType`/`DevEnvironment` fingerprint).
39    /// Get string representation
40    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    /// Get display name
50    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/// Development mode configuration
61#[allow(dead_code)]
62#[derive(Debug, Clone)]
63pub struct DevConfig {
64    /// Environment name
65    pub environment: DevEnvironment,
66    /// Enable hot reload/watch mode
67    pub watch: bool,
68    /// Skip initial build
69    pub no_build: bool,
70    /// Specific nodes to run (empty = all enabled nodes)
71    pub nodes: Vec<String>,
72    /// Auto-start services
73    pub auto_start_services: bool,
74    /// Flush Redis on start
75    pub flush_redis: bool,
76    /// Additional environment variables
77    pub env_vars: HashMap<String, String>,
78}
79
80#[allow(dead_code)]
81impl DevConfig {
82    /// Create a new dev config with defaults
83    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    /// Set watch mode
96    pub fn with_watch(mut self, enabled: bool) -> Self {
97        self.watch = enabled;
98        self
99    }
100
101    /// Set no-build flag
102    pub fn with_no_build(mut self, enabled: bool) -> Self {
103        self.no_build = enabled;
104        self
105    }
106
107    /// Set specific nodes to run
108    pub fn with_nodes(mut self, nodes: Vec<String>) -> Self {
109        self.nodes = nodes;
110        self
111    }
112
113    mecha10_core::builder_setter!(
114        /// Add a single node
115        push, with_node, nodes, impl Into<String>
116    );
117
118    /// Set auto-start services
119    pub fn with_auto_start_services(mut self, enabled: bool) -> Self {
120        self.auto_start_services = enabled;
121        self
122    }
123
124    /// Set flush Redis
125    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        /// Add environment variable
132        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}