cargo_smith/templates/
mod.rs1use core::fmt;
2
3use anyhow::Result;
4use async_trait::async_trait;
5use clap::ValueEnum;
6
7pub mod new;
8pub mod template_engine;
9pub mod types;
10
11use crate::templates::new::{traditional, nestjs};
12
13#[async_trait]
14pub trait Template {
15 fn name(&self) -> &str;
16 fn description(&self) -> &str;
17 async fn generate(&self, project_name: &str) -> Result<()>;
18}
19
20#[derive(ValueEnum, Clone, Debug)]
21pub enum TemplateType {
22 Traditional,
23 Nestjs,
24}
25
26impl fmt::Display for TemplateType {
27 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
28 match self {
29 TemplateType::Traditional => write!(f, "traditional"),
30 TemplateType::Nestjs => write!(f, "nestjs"),
31 }
32 }
33}
34
35impl TemplateType {
36 pub fn create(&self) -> Box<dyn Template> {
37 match self {
38 TemplateType::Traditional => Box::new(traditional::TraditionalTemplate),
39 TemplateType::Nestjs => Box::new(nestjs::NestJSTemplate),
40 }
41 }
42
43 pub fn list_available() -> Vec<(&'static str, &'static str)> {
44 vec![
45 ("traditional", "Traditional Rust/Actix structure (default)"),
46 ("nestjs", "NestJS-inspired modular structure"),
47 ]
48 }
49}