allframe_forge/
lib.rs

1//! AllFrame Forge - Project scaffolding library
2//!
3//! This library provides utilities for creating new AllFrame projects.
4//! It is used by the `allframe` CLI binary.
5
6#![deny(missing_docs)]
7
8pub mod scaffolding;
9pub mod templates;
10pub mod validation;
11
12use std::path::{Path, PathBuf};
13
14use clap::{Parser, Subcommand};
15
16#[derive(Parser)]
17#[command(name = "allframe")]
18#[command(about = "AllFrame CLI - The composable Rust API framework", long_about = None)]
19#[command(version)]
20struct Cli {
21    #[command(subcommand)]
22    command: Commands,
23}
24
25#[derive(Subcommand)]
26enum Commands {
27    /// Create a new AllFrame project
28    Ignite {
29        /// Name of the project to create
30        name: PathBuf,
31
32        /// Enable all features
33        #[arg(long)]
34        all_features: bool,
35    },
36    /// Generate code from LLM prompts (coming soon)
37    Forge {
38        /// The prompt for code generation
39        prompt: String,
40    },
41}
42
43/// Run the AllFrame CLI with command-line arguments.
44///
45/// This is the main entry point for the CLI, designed to be called from
46/// both the `allframe-forge` binary and the `allframe` binary wrapper.
47///
48/// # Errors
49/// Returns an error if command parsing fails or if the executed command fails.
50pub fn run() -> anyhow::Result<()> {
51    let cli = Cli::parse();
52
53    match cli.command {
54        Commands::Ignite { name, all_features } => {
55            ignite_project(&name, all_features)?;
56        }
57        Commands::Forge { prompt } => {
58            forge_code(&prompt)?;
59        }
60    }
61
62    Ok(())
63}
64
65/// Create a new AllFrame project
66///
67/// This function orchestrates the creation of a new AllFrame project with
68/// Clean Architecture structure.
69fn ignite_project(project_path: &Path, _all_features: bool) -> anyhow::Result<()> {
70    let project_name = project_path
71        .file_name()
72        .and_then(|n| n.to_str())
73        .ok_or_else(|| anyhow::anyhow!("Invalid project path"))?;
74
75    validation::validate_project_name(project_name)?;
76
77    if project_path.exists() {
78        anyhow::bail!("Directory already exists: {}", project_path.display());
79    }
80
81    std::fs::create_dir_all(project_path)?;
82
83    scaffolding::create_directory_structure(project_path)?;
84    scaffolding::generate_files(project_path, project_name)?;
85
86    println!("AllFrame project created successfully: {}", project_name);
87    println!("\nNext steps:");
88    println!("  cd {}", project_name);
89    println!("  cargo test");
90    println!("  cargo run");
91
92    Ok(())
93}
94
95/// Generate code from LLM prompts (not yet implemented)
96fn forge_code(_prompt: &str) -> anyhow::Result<()> {
97    anyhow::bail!("allframe forge is not yet implemented")
98}