use clap::{CommandFactory, Parser, Subcommand};
mod commands;
#[derive(Parser)]
#[command(name = "rejoice")]
#[command(about = "A simple and delightful little web framework for Rust")]
#[command(version)]
struct Cli {
#[command(subcommand)]
command: Option<Commands>,
}
#[derive(Subcommand)]
enum Commands {
Init {
name: Option<String>,
#[arg(long)]
with_db: bool,
},
Dev,
Build {
#[arg(long)]
release: bool,
},
Migrate {
#[command(subcommand)]
action: MigrateAction,
},
}
#[derive(Subcommand)]
enum MigrateAction {
Add {
name: String,
},
Up,
Revert,
Status,
}
fn main() {
let cli = Cli::parse();
match cli.command {
Some(Commands::Init { name, with_db }) => {
commands::init_command(name.as_ref(), with_db);
}
Some(Commands::Dev) => {
commands::dev_command();
}
Some(Commands::Build { release }) => {
commands::build_command(release);
}
Some(Commands::Migrate { action }) => match action {
MigrateAction::Add { name } => commands::migrate_add(&name),
MigrateAction::Up => commands::migrate_up(),
MigrateAction::Revert => commands::migrate_revert(),
MigrateAction::Status => commands::migrate_status(),
},
None => {
Cli::command().print_help().unwrap();
}
}
}