mecha10-cli 0.6.5

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

use std::collections::HashMap;

/// Development environment configuration
#[allow(dead_code)]
#[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)]
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()),
        }
    }

    // duplicate: false positive — matches `DriverType::as_str` (mecha10-templates) and
    // `StartTarget::as_str` (launcher-service) on the match-per-variant-returning-&str AST
    // shape, but `DevEnvironment` has a data-carrying `Custom(String)` variant that returns
    // `s.as_str()` instead of a literal, so it doesn't fit the workspace's `enum_str_method!`
    // macro (fieldless-variant, one-literal-per-arm shape only) those two otherwise share; no
    // helper covers both shapes (see `.dupes-ignore.toml`'s matching entry for the pairwise
    // `DriverType`/`DevEnvironment` fingerprint).
    /// 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)]
#[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)]
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
    }

    mecha10_core::builder_setter!(
        /// Add a single node
        push, with_node, nodes, impl Into<String>
    );

    /// 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
    }

    mecha10_core::builder_setter!(
        /// Add environment variable
        insert, with_env_var, env_vars, impl Into<String>, impl Into<String>
    );
}

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