use clap::{Args, Parser, Subcommand, ValueEnum};
use std::path::PathBuf;
#[derive(Parser, Debug)]
#[command(name = "prax")]
#[command(author = "Pegasus Heavy Industries LLC")]
#[command(version)]
#[command(about = "Prax CLI - A modern ORM for Rust", long_about = None)]
#[command(propagate_version = true)]
pub struct Cli {
#[command(subcommand)]
pub command: Command,
}
#[derive(Subcommand, Debug)]
pub enum Command {
Init(InitArgs),
Generate(GenerateArgs),
Validate(ValidateArgs),
Format(FormatArgs),
Migrate(MigrateArgs),
Db(DbArgs),
Version,
}
#[derive(Args, Debug)]
pub struct InitArgs {
#[arg(default_value = ".")]
pub path: PathBuf,
#[arg(short, long, default_value = "postgresql")]
pub provider: DatabaseProvider,
#[arg(short, long)]
pub url: Option<String>,
#[arg(long)]
pub no_example: bool,
#[arg(short, long)]
pub yes: bool,
}
#[derive(ValueEnum, Debug, Clone, Copy, Default)]
pub enum DatabaseProvider {
#[default]
Postgresql,
Mysql,
Sqlite,
}
impl std::fmt::Display for DatabaseProvider {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
DatabaseProvider::Postgresql => write!(f, "postgresql"),
DatabaseProvider::Mysql => write!(f, "mysql"),
DatabaseProvider::Sqlite => write!(f, "sqlite"),
}
}
}
#[derive(Args, Debug)]
pub struct GenerateArgs {
#[arg(short, long)]
pub schema: Option<PathBuf>,
#[arg(short, long)]
pub output: Option<PathBuf>,
#[arg(short, long, value_delimiter = ',')]
pub features: Vec<String>,
#[arg(short, long)]
pub watch: bool,
}
#[derive(Args, Debug)]
pub struct ValidateArgs {
#[arg(short, long)]
pub schema: Option<PathBuf>,
}
#[derive(Args, Debug)]
pub struct FormatArgs {
#[arg(short, long)]
pub schema: Option<PathBuf>,
#[arg(short, long)]
pub check: bool,
}
#[derive(Args, Debug)]
pub struct MigrateArgs {
#[command(subcommand)]
pub command: MigrateSubcommand,
}
#[derive(Subcommand, Debug)]
pub enum MigrateSubcommand {
Dev(MigrateDevArgs),
Deploy,
Reset(MigrateResetArgs),
Status,
Resolve(MigrateResolveArgs),
Diff(MigrateDiffArgs),
}
#[derive(Args, Debug)]
pub struct MigrateDevArgs {
#[arg(short, long)]
pub name: Option<String>,
#[arg(long)]
pub create_only: bool,
#[arg(long)]
pub skip_seed: bool,
#[arg(short, long)]
pub schema: Option<PathBuf>,
}
#[derive(Args, Debug)]
pub struct MigrateResetArgs {
#[arg(short, long)]
pub force: bool,
#[arg(long)]
pub seed: bool,
#[arg(long)]
pub skip_migrations: bool,
}
#[derive(Args, Debug)]
pub struct MigrateResolveArgs {
pub migration: String,
#[arg(long)]
pub applied: bool,
#[arg(long)]
pub rolled_back: bool,
}
#[derive(Args, Debug)]
pub struct MigrateDiffArgs {
#[arg(short, long)]
pub schema: Option<PathBuf>,
#[arg(short, long)]
pub output: Option<PathBuf>,
#[arg(long)]
pub from_migration: Option<String>,
}
#[derive(Args, Debug)]
pub struct DbArgs {
#[command(subcommand)]
pub command: DbSubcommand,
}
#[derive(Subcommand, Debug)]
pub enum DbSubcommand {
Push(DbPushArgs),
Pull(DbPullArgs),
Seed(DbSeedArgs),
Execute(DbExecuteArgs),
}
#[derive(Args, Debug)]
pub struct DbPushArgs {
#[arg(short, long)]
pub schema: Option<PathBuf>,
#[arg(long)]
pub accept_data_loss: bool,
#[arg(short, long)]
pub force: bool,
#[arg(long)]
pub reset: bool,
}
#[derive(Args, Debug)]
pub struct DbPullArgs {
#[arg(short, long)]
pub output: Option<PathBuf>,
#[arg(short, long)]
pub force: bool,
#[arg(long)]
pub include_views: bool,
}
#[derive(Args, Debug)]
pub struct DbSeedArgs {
#[arg(short, long)]
pub seed_file: Option<PathBuf>,
#[arg(long)]
pub reset: bool,
#[arg(short, long, default_value = "development")]
pub environment: String,
#[arg(short, long)]
pub force: bool,
}
#[derive(Args, Debug)]
pub struct DbExecuteArgs {
#[arg(short, long)]
pub sql: Option<String>,
#[arg(short, long)]
pub file: Option<PathBuf>,
#[arg(long)]
pub stdin: bool,
#[arg(short = 'y', long)]
pub force: bool,
}