mecha10-cli 0.7.0

Mecha10 CLI tool
Documentation
//! Node selection logic for development mode

use crate::types::{NodeSpec, ProjectConfig};

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct NodeToRun {
    pub name: String,
    pub identifier: String,
    pub path: String,
    pub is_framework_node: bool,
}

impl NodeToRun {
    /// Create a new NodeToRun from NodeSpec
    pub fn from_spec(spec: &NodeSpec) -> Self {
        Self {
            name: spec.name.clone(),
            identifier: spec.identifier.clone(),
            path: spec.package_path(),
            is_framework_node: spec.is_framework(),
        }
    }
}

/// Get list of nodes to run based on configuration
///
/// # Arguments
///
/// * `requested_nodes` - Specific nodes requested by user (empty = all nodes)
/// * `project_config` - Project configuration
///
/// # Returns
///
/// List of nodes to run
pub fn get_nodes_to_run(requested_nodes: &[String], project_config: &ProjectConfig) -> Vec<NodeToRun> {
    let all_specs = project_config.nodes.get_node_specs();

    let specs_to_run: Vec<NodeSpec> = if requested_nodes.is_empty() {
        all_specs
    } else {
        all_specs
            .into_iter()
            .filter(|s| requested_nodes.contains(&s.name))
            .collect()
    };

    specs_to_run.iter().map(NodeToRun::from_spec).collect()
}

/// Get list of all available node names
pub fn get_available_node_names(project_config: &ProjectConfig) -> Vec<String> {
    project_config.nodes.get_node_names()
}

/// Get list of enabled node names
///
/// Note: In the new format, all nodes in the list are considered "enabled".
/// Use lifecycle modes to control which nodes run in different contexts.
#[allow(dead_code)]
pub fn get_enabled_node_names(project_config: &ProjectConfig) -> Vec<String> {
    project_config.nodes.get_node_names()
}

/// Check if a node is a framework node by name
#[allow(dead_code)]
pub fn is_framework_node(project_config: &ProjectConfig, name: &str) -> bool {
    project_config
        .nodes
        .find_by_name(name)
        .map(|s| s.is_framework())
        .unwrap_or(false)
}