Skip to main content

mecha10_cli/dev/
node_selection.rs

1//! Node selection logic for development mode
2
3use crate::types::{NodeSpec, ProjectConfig};
4
5#[derive(Debug, Clone, PartialEq, Eq)]
6pub struct NodeToRun {
7    pub name: String,
8    pub identifier: String,
9    pub path: String,
10    pub is_framework_node: bool,
11}
12
13impl NodeToRun {
14    /// Create a new NodeToRun from NodeSpec
15    pub fn from_spec(spec: &NodeSpec) -> Self {
16        Self {
17            name: spec.name.clone(),
18            identifier: spec.identifier.clone(),
19            path: spec.package_path(),
20            is_framework_node: spec.is_framework(),
21        }
22    }
23}
24
25/// Get list of nodes to run based on configuration
26///
27/// # Arguments
28///
29/// * `requested_nodes` - Specific nodes requested by user (empty = all nodes)
30/// * `project_config` - Project configuration
31///
32/// # Returns
33///
34/// List of nodes to run
35pub fn get_nodes_to_run(requested_nodes: &[String], project_config: &ProjectConfig) -> Vec<NodeToRun> {
36    let all_specs = project_config.nodes.get_node_specs();
37
38    let specs_to_run: Vec<NodeSpec> = if requested_nodes.is_empty() {
39        all_specs
40    } else {
41        all_specs
42            .into_iter()
43            .filter(|s| requested_nodes.contains(&s.name))
44            .collect()
45    };
46
47    specs_to_run.iter().map(NodeToRun::from_spec).collect()
48}
49
50/// Get list of all available node names
51pub fn get_available_node_names(project_config: &ProjectConfig) -> Vec<String> {
52    project_config.nodes.get_node_names()
53}
54
55/// Get list of enabled node names
56///
57/// Note: In the new format, all nodes in the list are considered "enabled".
58/// Use lifecycle modes to control which nodes run in different contexts.
59#[allow(dead_code)]
60pub fn get_enabled_node_names(project_config: &ProjectConfig) -> Vec<String> {
61    project_config.nodes.get_node_names()
62}
63
64/// Check if a node is a framework node by name
65#[allow(dead_code)]
66pub fn is_framework_node(project_config: &ProjectConfig, name: &str) -> bool {
67    project_config
68        .nodes
69        .find_by_name(name)
70        .map(|s| s.is_framework())
71        .unwrap_or(false)
72}