use std::path::Path;
use colored::Colorize;
use anyhow::{Result, Context};
use crate::core::presets::all_presets;
use crate::core::registry::RecipeRegistry;
use crate::utils::terminal;
pub fn list() -> Result<()> {
println!();
println!("{}", terminal::label("Available Presets:"));
println!("{}", terminal::label("─".repeat(50).as_str()));
let registry = RecipeRegistry::new();
for preset in all_presets() {
use crate::core::presets::RiskLevel;
let risk_str = match preset.risk_level {
RiskLevel::Low => format!("{}", "low".bold().green()),
RiskLevel::Medium => format!("{}", "medium".bold().yellow()),
RiskLevel::High => format!("{}", "high".bold().red()),
};
let mut recipe_parts = Vec::new();
for &recipe_name in preset.recipes {
if let Some(recipe) = registry.find(recipe_name) {
recipe_parts.push(format!("{} (category: {})", recipe_name, recipe.metadata().category));
} else {
recipe_parts.push(recipe_name.to_string());
}
}
println!(" {} - {}", terminal::label(preset.name), preset.description);
println!(" Recipes: {}", recipe_parts.join(", "));
println!(" Risk: {}", risk_str);
println!();
}
Ok(())
}
pub fn run(name: &str, path: &Path, write: bool, project_root: &Path) -> Result<()> {
let preset = crate::core::presets::find_preset(name)
.with_context(|| format!("Preset not found: {}", name))?;
let mut registry = RecipeRegistry::new();
registry.load_plugins(path);
let mut recipe_parts = Vec::new();
for &recipe_name in preset.recipes {
if let Some(recipe) = registry.find(recipe_name) {
recipe_parts.push(format!("{} (category: {})", recipe_name, recipe.metadata().category));
} else {
recipe_parts.push(recipe_name.to_string());
}
}
println!();
println!("{} Running preset: {}", terminal::success_prefix(), terminal::label(preset.name));
println!(" Description: {}", preset.description);
println!(" Recipes: {}", recipe_parts.join(", "));
println!(" Risk Level: {:?}", preset.risk_level);
println!(" Flags: review={}, allow_risky={}, strict={}",
preset.recommended_flags.review,
preset.recommended_flags.allow_risky,
preset.recommended_flags.strict
);
let recipes: Vec<String> = preset.recipes.iter().map(|&s| s.to_string()).collect();
crate::commands::run::execute(
&recipes,
path,
!write, write,
preset.recommended_flags.review,
false, false, false, None, preset.recommended_flags.allow_risky,
preset.recommended_flags.strict,
false, false, Path::new(".morph-cli/reports"), false, false, false, None, false, project_root,
None, None, None, None, )
}