#![forbid(unsafe_code)]
mod build;
mod db;
mod deploy;
mod dev;
mod make;
mod new;
mod util;
use clap::{Parser, Subcommand};
#[derive(Parser)]
#[command(name = "chy", version, about = "🥁 Chyabrung — build with rhythm", propagate_version = true)]
struct Cli {
#[command(subcommand)]
cmd: Cmd,
}
#[derive(Subcommand)]
enum Cmd {
New {
name: String,
#[arg(short, long, default_value = "api")]
template: String,
#[arg(long)]
chyabrung_path: Option<String>,
},
Dev {
#[arg(long)]
features: Option<String>,
#[arg(long, default_value_t = 35729)]
reload_port: u16,
},
Build {
#[arg(long = "static")]
static_site: bool,
#[arg(long)]
no_wasm: bool,
},
#[command(name = "make:model")]
MakeModel {
name: String,
#[arg(short, long)]
migration: bool,
},
#[command(name = "make:controller")]
MakeController { name: String },
#[command(name = "make:migration")]
MakeMigration { name: String },
#[command(name = "make:middleware")]
MakeMiddleware { name: String },
#[command(name = "make:job")]
MakeJob { name: String },
#[command(name = "make:page")]
MakePage { path: String },
#[command(name = "make:seeder")]
MakeSeeder { name: String },
Migrate,
#[command(name = "migrate:rollback")]
MigrateRollback {
#[arg(long, default_value_t = 1)]
step: u32,
},
#[command(name = "migrate:status")]
MigrateStatus,
#[command(name = "migrate:fresh")]
MigrateFresh,
#[command(name = "db:seed")]
DbSeed,
#[command(name = "key:generate")]
KeyGenerate {
#[arg(long)]
show: bool,
},
Deploy {
#[arg(long)]
dry_run: bool,
},
}
fn main() {
let cli = Cli::parse();
let result = match cli.cmd {
Cmd::New { name, template, chyabrung_path } => new::run(&name, &template, chyabrung_path.as_deref()),
Cmd::Dev { features, reload_port } => dev::run(features.as_deref(), reload_port),
Cmd::Build { static_site, no_wasm } => build::run(static_site, !no_wasm),
Cmd::MakeModel { name, migration } => make::model(&name, migration),
Cmd::MakeController { name } => make::controller(&name),
Cmd::MakeMigration { name } => make::migration(&name).map(|_| ()),
Cmd::MakeMiddleware { name } => make::middleware(&name),
Cmd::MakeJob { name } => make::job(&name),
Cmd::MakePage { path } => make::page(&path),
Cmd::MakeSeeder { name } => make::seeder(&name),
Cmd::Migrate => db::migrate(),
Cmd::MigrateRollback { step } => db::rollback(step),
Cmd::MigrateStatus => db::status(),
Cmd::MigrateFresh => db::fresh(),
Cmd::DbSeed => db::seed(),
Cmd::KeyGenerate { show } => util::key_generate(show),
Cmd::Deploy { dry_run } => deploy::run(dry_run),
};
if let Err(e) = result {
eprintln!("\x1b[31merror:\x1b[0m {e}");
std::process::exit(1);
}
}