mecha10-cli 0.1.47

Mecha10 CLI tool
Documentation
//! Domain types for development mode

use std::collections::HashMap;

/// Development environment configuration
#[allow(dead_code)] // Tested, planned for future use
#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub enum DevEnvironment {
    /// Local development
    #[default]
    Dev,
    /// Staging environment
    Staging,
    /// Production environment
    Production,
    /// Custom environment
    Custom(String),
}

#[allow(dead_code)] // Tested, planned for future use
impl DevEnvironment {
    /// Parse from string
    pub fn parse_environment(s: &str) -> Self {
        match s.to_lowercase().as_str() {
            "dev" | "development" => Self::Dev,
            "staging" | "stage" => Self::Staging,
            "production" | "prod" => Self::Production,
            _ => Self::Custom(s.to_string()),
        }
    }

    /// Get string representation
    pub fn as_str(&self) -> &str {
        match self {
            Self::Dev => "dev",
            Self::Staging => "staging",
            Self::Production => "production",
            Self::Custom(s) => s.as_str(),
        }
    }

    /// Get display name
    pub fn display_name(&self) -> String {
        match self {
            Self::Dev => "Development".to_string(),
            Self::Staging => "Staging".to_string(),
            Self::Production => "Production".to_string(),
            Self::Custom(s) => s.clone(),
        }
    }
}

/// Development mode configuration
#[allow(dead_code)] // Tested, planned for future use
#[derive(Debug, Clone)]
pub struct DevConfig {
    /// Environment name
    pub environment: DevEnvironment,
    /// Enable hot reload/watch mode
    pub watch: bool,
    /// Skip initial build
    pub no_build: bool,
    /// Specific nodes to run (empty = all enabled nodes)
    pub nodes: Vec<String>,
    /// Auto-start services
    pub auto_start_services: bool,
    /// Flush Redis on start
    pub flush_redis: bool,
    /// Additional environment variables
    pub env_vars: HashMap<String, String>,
}

#[allow(dead_code)] // Tested, planned for future use
impl DevConfig {
    /// Create a new dev config with defaults
    pub fn new(environment: DevEnvironment) -> Self {
        Self {
            environment,
            watch: false,
            no_build: false,
            nodes: Vec::new(),
            auto_start_services: true,
            flush_redis: true,
            env_vars: HashMap::new(),
        }
    }

    /// Set watch mode
    pub fn with_watch(mut self, enabled: bool) -> Self {
        self.watch = enabled;
        self
    }

    /// Set no-build flag
    pub fn with_no_build(mut self, enabled: bool) -> Self {
        self.no_build = enabled;
        self
    }

    /// Set specific nodes to run
    pub fn with_nodes(mut self, nodes: Vec<String>) -> Self {
        self.nodes = nodes;
        self
    }

    /// Add a single node
    pub fn with_node(mut self, node: impl Into<String>) -> Self {
        self.nodes.push(node.into());
        self
    }

    /// Set auto-start services
    pub fn with_auto_start_services(mut self, enabled: bool) -> Self {
        self.auto_start_services = enabled;
        self
    }

    /// Set flush Redis
    pub fn with_flush_redis(mut self, enabled: bool) -> Self {
        self.flush_redis = enabled;
        self
    }

    /// Add environment variable
    pub fn with_env_var(mut self, key: impl Into<String>, value: impl Into<String>) -> Self {
        self.env_vars.insert(key.into(), value.into());
        self
    }

    /// Add multiple environment variables
    pub fn with_env_vars(mut self, vars: HashMap<String, String>) -> Self {
        self.env_vars.extend(vars);
        self
    }
}

impl Default for DevConfig {
    fn default() -> Self {
        Self::new(DevEnvironment::default())
    }
}