41 lines
826 B
Rust
41 lines
826 B
Rust
use achubb_backend::{run_create, run_load, run_server, database::establish_connection};
|
|
use clap::Parser;
|
|
use std::error::Error;
|
|
use sqlx::postgres::PgPool;
|
|
|
|
#[derive(Parser, Debug)]
|
|
#[command(version, about, long_about = None)]
|
|
struct Args {
|
|
#[arg(short, long)]
|
|
setup: bool,
|
|
|
|
#[arg(short, long)]
|
|
load: bool,
|
|
|
|
#[arg(short, long)]
|
|
run: bool,
|
|
}
|
|
|
|
#[tokio::main]
|
|
async fn main() -> Result<(), Box<dyn Error>> {
|
|
let args = Args::parse();
|
|
|
|
let pool: PgPool = match establish_connection().await {
|
|
Ok(p) => p,
|
|
Err(_) => panic!("error connecting to database"),
|
|
};
|
|
|
|
if args.setup {
|
|
run_create(&pool).await?
|
|
}
|
|
|
|
if args.load {
|
|
run_load(&pool).await?;
|
|
}
|
|
|
|
if args.run || !(args.load || args.setup) {
|
|
run_server(pool).await?;
|
|
}
|
|
Ok(())
|
|
}
|