use anyhow::Result;
use clap::{Parser, Subcommand};
mod commands;
mod config;
mod generator;
mod introspect;
mod sql_generator;
mod tracker;
#[derive(Parser)]
#[command(name = "ormada")]
#[command(author = "Stanislav Petrov <slavpetroff@gmail.com>")]
#[command(version = "0.1.0")]
#[command(about = "Ormada ORM CLI - Database migration management", long_about = None)]
struct Cli {
#[command(subcommand)]
command: Commands,
}
#[derive(Subcommand)]
enum Commands {
Migrate {
#[command(subcommand)]
action: MigrateAction,
},
}
#[derive(Subcommand)]
enum MigrateAction {
Make {
name: String,
#[arg(short = 'y', long)]
yes: bool,
},
Run {
#[arg(long)]
migration: Option<String>,
#[arg(long)]
dry_run: bool,
},
Status,
Rollback {
#[arg(short, long, default_value = "1")]
steps: u32,
#[arg(short = 'y', long)]
yes: bool,
},
Sql {
#[arg(short, long)]
output: Option<String>,
},
Init {
#[arg(short, long)]
path: Option<String>,
},
}
#[tokio::main]
async fn main() -> Result<()> {
let cli = Cli::parse();
match cli.command {
Commands::Migrate { action } => match action {
MigrateAction::Make { name, yes } => {
commands::migrate_make(&name, yes).await?;
}
MigrateAction::Run { migration, dry_run } => {
commands::migrate_run(migration.as_deref(), dry_run).await?;
}
MigrateAction::Status => {
commands::migrate_status().await?;
}
MigrateAction::Rollback { steps, yes } => {
commands::migrate_rollback(steps, yes).await?;
}
MigrateAction::Sql { output } => {
commands::migrate_sql(output.as_deref()).await?;
}
MigrateAction::Init { path } => {
commands::migrate_init(path.as_deref()).await?;
}
},
}
Ok(())
}