mecha10-cli 0.1.47

Mecha10 CLI tool
Documentation
#![allow(dead_code)]

//! Component Catalog for Mecha10
//!
//! This module defines the catalog of available components that can be added to a project.
//! Each component includes metadata, dependencies, and templates for code generation.
//!
//! The catalog is broken into submodules to keep file sizes manageable:
//! - `types`: Core data types
//! - `drivers`: Driver component definitions
//! - `packages`: Package component definitions
//! - `behaviors`: Behavior component definitions
//! - `stacks`: Stack component definitions

mod behaviors;
mod drivers;
mod packages;
mod stacks;
mod types;

// Re-export types
pub use types::*;

use std::collections::HashMap;

/// Component catalog
pub struct ComponentCatalog {
    components: HashMap<String, Component>,
}

impl ComponentCatalog {
    /// Create a new component catalog with built-in components
    pub fn new() -> Self {
        let mut catalog = Self {
            components: HashMap::new(),
        };

        // Add built-in components from each category
        catalog.add_driver_components();
        catalog.add_package_components();
        catalog.add_behavior_components();
        catalog.add_stack_components();

        catalog
    }

    /// Get all components
    #[allow(dead_code)]
    pub fn get_all(&self) -> Vec<&Component> {
        self.components.values().collect()
    }

    /// Get components by type
    pub fn get_by_type(&self, component_type: ComponentType) -> Vec<&Component> {
        self.components
            .values()
            .filter(|c| c.component_type == component_type)
            .collect()
    }

    /// Get a component by ID
    pub fn get(&self, id: &str) -> Option<&Component> {
        self.components.get(id)
    }

    /// Search components by query
    pub fn search(&self, query: &str) -> Vec<&Component> {
        let query_lower = query.to_lowercase();
        self.components
            .values()
            .filter(|c| {
                c.name.to_lowercase().contains(&query_lower)
                    || c.description.to_lowercase().contains(&query_lower)
                    || c.tags.iter().any(|t| t.to_lowercase().contains(&query_lower))
            })
            .collect()
    }

    /// Insert a component into the catalog
    fn insert(&mut self, component: Component) {
        self.components.insert(component.id.clone(), component);
    }

    /// Add driver components to the catalog
    fn add_driver_components(&mut self) {
        drivers::add_drivers(self);
    }

    /// Add package components to the catalog
    fn add_package_components(&mut self) {
        packages::add_packages(self);
    }

    /// Add behavior components to the catalog
    fn add_behavior_components(&mut self) {
        behaviors::add_behaviors(self);
    }

    /// Add stack components to the catalog
    fn add_stack_components(&mut self) {
        stacks::add_stacks(self);
    }
}

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