ferrous_forge/commands/template/
mod.rs1use crate::Result;
4use crate::templates::TemplateRegistry;
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#[derive(Debug, Subcommand)]
19pub enum TemplateCommand {
20 List,
22
23 Create {
25 template: String,
27
28 output: PathBuf,
30
31 #[arg(long = "var", short = 'v')]
33 variables: Vec<String>,
34 },
35
36 Info {
38 template: String,
40 },
41
42 Validate {
44 manifest: PathBuf,
46 },
47}
48
49impl TemplateCommand {
50 pub async fn execute(&self) -> Result<()> {
57 match self {
58 TemplateCommand::List => {
59 println!(
60 "{}",
61 style("📚 Available Ferrous Forge Templates").cyan().bold()
62 );
63 println!();
64
65 let registry = TemplateRegistry::new();
66 let templates = registry.list_templates();
67
68 if templates.is_empty() {
69 println!(" No templates found.");
70 return Ok(());
71 }
72
73 for (name, _kind, description) in &templates {
74 println!(" {} {}", style("•").cyan(), style(name).white().bold());
75 println!(" {}", style(description).dim());
76 println!();
77 }
78
79 println!(
80 "Use {} to create a project from a template.",
81 style("ferrous-forge template create <template-name> <output-dir>").cyan()
82 );
83 println!(
84 "Use {} to see detailed information about a template.",
85 style("ferrous-forge template info <template-name>").cyan()
86 );
87 Ok(())
88 }
89
90 TemplateCommand::Create {
91 template,
92 output,
93 variables,
94 } => create_from_template(template, output, variables).await,
95
96 TemplateCommand::Info { template } => show_template_info(template).await,
97
98 TemplateCommand::Validate { manifest } => validate_template_manifest(manifest).await,
99 }
100 }
101}