morph-cli 0.1.0

AST-based codebase migration and codemod tool for JavaScript and TypeScript projects.
Documentation
use anyhow::Result;
use std::path::Path;
use crate::core::registry::RecipeRegistry;
use crate::utils::terminal;

pub fn execute(path: &Path, category_filter: Option<&str>, tag_filter: Option<&str>) -> Result<()> {
    if let Some(cat) = category_filter {
        if let Some(t) = tag_filter {
            terminal::print_info(&format!("Available recipes in category '{}' with tag '{}':", cat, t));
        } else {
            terminal::print_info(&format!("Available recipes in category '{}':", cat));
        }
    } else if let Some(t) = tag_filter {
        terminal::print_info(&format!("Available recipes with tag '{}':", t));
    } else {
        terminal::print_info("Available recipes:");
    }

    let mut registry = RecipeRegistry::new();
    registry.load_plugins(path);
    for recipe in registry.all() {
        let metadata = recipe.metadata();

        if let Some(cat_str) = category_filter {
            if metadata.category.to_string().to_lowercase() != cat_str.to_lowercase() {
                continue;
            }
        }

        if let Some(tag_str) = tag_filter {
            if !metadata.tags.iter().any(|t| t.to_lowercase() == tag_str.to_lowercase()) {
                continue;
            }
        }

        println!(
            "  {} {} [{}] [category: {}]",
            terminal::bullet(),
            metadata.name,
            metadata.maturity,
            metadata.category
        );
        println!("    {}", metadata.description);
        if !metadata.tags.is_empty() {
            println!("    Tags: {}", metadata.tags.join(", "));
        }
    }

    Ok(())
}