mod commands;
use anyhow::Result;
use clap::{Parser, Subcommand};
#[derive(Parser)]
#[command(name = "au")]
#[command(version, about, long_about = None)]
#[command(author = "AuDB Contributors")]
struct Cli {
#[command(subcommand)]
command: Commands,
}
#[derive(Subcommand)]
enum Commands {
Init {
name: String,
#[arg(short, long, default_value = "server")]
template: String,
#[arg(long)]
no_git: bool,
},
Generate {
#[arg(short, long, default_value = "./gold")]
gold_dir: String,
#[arg(short, long, default_value = "./src/generated")]
output_dir: String,
},
Check {
#[arg(short, long, default_value = "./gold")]
gold_dir: String,
},
Dev {
#[arg(short, long, default_value = "./gold")]
gold_dir: String,
#[arg(short, long, default_value = "./src/generated")]
output_dir: String,
},
Deploy {
#[command(subcommand)]
command: Option<DeploySubcommand>,
#[arg(short, long)]
target: Option<String>,
#[arg(short, long)]
port: Option<u16>,
#[arg(short, long)]
env: Vec<String>,
#[arg(short, long)]
volume: Vec<String>,
#[arg(long)]
force_rebuild: bool,
#[arg(long)]
compose: bool,
},
}
#[derive(Subcommand)]
enum DeploySubcommand {
Start,
Status,
Stop,
Logs,
Restart,
}
#[tokio::main]
async fn main() -> Result<()> {
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init();
let cli = Cli::parse();
match cli.command {
Commands::Init {
name,
template,
no_git,
} => {
commands::init::run(&name, &template, !no_git).await?;
}
Commands::Generate {
gold_dir,
output_dir,
} => {
commands::generate::run(&gold_dir, &output_dir)?;
}
Commands::Check { gold_dir } => {
commands::check::run(&gold_dir)?;
}
Commands::Dev {
gold_dir,
output_dir,
} => {
commands::dev::run(&gold_dir, &output_dir)?;
}
Commands::Deploy {
command,
target,
port,
env,
volume,
force_rebuild,
compose,
} => {
let deploy_cmd = match command {
Some(DeploySubcommand::Start) | None => commands::deploy::DeployCommand::Start,
Some(DeploySubcommand::Status) => commands::deploy::DeployCommand::Status,
Some(DeploySubcommand::Stop) => commands::deploy::DeployCommand::Stop,
Some(DeploySubcommand::Logs) => commands::deploy::DeployCommand::Logs,
Some(DeploySubcommand::Restart) => commands::deploy::DeployCommand::Restart,
};
let options = commands::deploy::DeployOptions {
target,
port,
env,
volume,
force_rebuild,
compose,
};
commands::deploy::run(deploy_cmd, options).await?;
}
}
Ok(())
}