ferrous_forge/commands/template/
mod.rs

1//! Template management commands
2
3use crate::templates::TemplateRegistry;
4use crate::Result;
5use clap::Subcommand;
6use console::style;
7use std::path::PathBuf;
8
9mod creation;
10mod display;
11mod utils;
12
13pub use creation::*;
14pub use display::*;
15pub use utils::*;
16
17/// Template subcommands
18#[derive(Debug, Subcommand)]
19pub enum TemplateCommand {
20    /// List available templates
21    List,
22
23    /// Create a new project from template
24    Create {
25        /// Template name
26        template: String,
27
28        /// Output directory
29        output: PathBuf,
30
31        /// Template variables in key=value format
32        #[arg(long = "var", short = 'v')]
33        variables: Vec<String>,
34    },
35
36    /// Show detailed information about a template
37    Info {
38        /// Template name
39        template: String,
40    },
41
42    /// Validate a template manifest
43    Validate {
44        /// Path to template manifest
45        manifest: PathBuf,
46    },
47}
48
49impl TemplateCommand {
50    /// Execute the template command
51    pub async fn execute(&self) -> Result<()> {
52        match self {
53            TemplateCommand::List => {
54                println!(
55                    "{}",
56                    style("📚 Available Ferrous Forge Templates").cyan().bold()
57                );
58                println!();
59
60                let registry = TemplateRegistry::new();
61                let templates = registry.list_templates();
62
63                if templates.is_empty() {
64                    println!("   No templates found.");
65                    return Ok(());
66                }
67
68                for (name, _kind, description) in &templates {
69                    println!("  {} {}", style("•").cyan(), style(name).white().bold());
70                    println!("    {}", style(description).dim());
71                    println!();
72                }
73
74                println!(
75                    "Use {} to create a project from a template.",
76                    style("ferrous-forge template create <template-name> <output-dir>").cyan()
77                );
78                println!(
79                    "Use {} to see detailed information about a template.",
80                    style("ferrous-forge template info <template-name>").cyan()
81                );
82                Ok(())
83            }
84
85            TemplateCommand::Create {
86                template,
87                output,
88                variables,
89            } => create_from_template(template, output, variables).await,
90
91            TemplateCommand::Info { template } => show_template_info(template).await,
92
93            TemplateCommand::Validate { manifest } => validate_template_manifest(manifest).await,
94        }
95    }
96}