mod commands;
mod types;
use anyhow::Result;
use clap::{Parser, Subcommand, ValueEnum};
use commands::{gen::GenKind, MigrateAction};
#[derive(Parser)]
#[command(
name = "keg",
version,
author = "Your Name <you@example.com>",
about = "Kegani: a developer-friendly, ergonomic, production-ready Rust web framework",
long_about = "Kegani — A complete Rust web framework in a single binary
Commands:
init Create a complete project with layered architecture
gen Generate code: api, model, service, repository, controller, middleware, migration
run Run the application with hot reload (file watching)
build Build a release binary (cross-compile supported)
docker Generate Dockerfile and docker-compose.yml
env Print environment diagnostics
up Update Kegani framework and CLI
migrate Run database migrations (up, down, status, reset)
clean Remove build artifacts
Examples:
keg init my-api Create a new project
keg gen api article Generate full CRUD stack
keg gen model user Generate entity
keg gen migration create_users Generate SQL migration
keg run Run with hot reload
keg docker Generate Docker files
keg build --target x86_64-unknown-linux-musl"
)]
struct Cli {
#[command(subcommand)]
command: Commands,
}
#[derive(Subcommand)]
enum Commands {
Init {
name: String,
#[arg(short, long, default_value = "api")]
template: String,
},
Gen {
#[arg(value_enum)]
kind: GenKind,
name: String,
},
Run {
#[arg(short, long, default_value = "8080")]
port: u16,
#[arg(short, long, default_value = "true")]
watch: bool,
},
Build {
#[arg(short, long)]
target: Option<String>,
},
Docker,
Env,
Up,
Migrate {
#[arg(value_enum)]
action: MigrateAction,
},
Clean {
#[arg(short, long, default_value = "false")]
all: bool,
},
}
fn main() -> Result<()> {
let cli = Cli::parse();
match cli.command {
Commands::Init { name, template } => commands::init::init(&name, &template)?,
Commands::Gen { kind, name } => commands::gen::gen(kind, &name)?,
Commands::Run { port, watch } => commands::run::run(port, watch)?,
Commands::Build { target } => commands::build::build(target.as_deref())?,
Commands::Docker => commands::docker::docker()?,
Commands::Env => commands::env::env()?,
Commands::Up => commands::update::update()?,
Commands::Migrate { action } => commands::migrate::run_migration(action)?,
Commands::Clean { all } => commands::clean::clean(all)?,
}
Ok(())
}