backend/main.rs

63 lines
1.2 KiB
Rust
Raw Normal View History

2024-06-21 20:50:47 +02:00
use clap::{Parser, Subcommand};
/// Super Cool Chat Thing c:
#[derive(Parser)]
struct Args {
#[clap(subcommand)]
cmd: Command,
#[arg(long, default_value = "sqlite://./scct.db")]
/// connection string to database
db: String,
#[arg(long)]
/// run with debug log level
debug: bool,
}
#[derive(Clone, Subcommand)]
enum Command {
#[cfg(feature = "migrations")]
/// apply scct migrations
Migrate,
#[cfg(feature = "server")]
/// run scct server
Serve {
/// address+port to bind onto
#[arg(short, long, default_value = "127.0.0.1:8424")]
addr: String,
}
}
#[async_std::main]
2024-06-21 20:50:47 +02:00
async fn main() {
let args = Args::parse();
tracing_subscriber::fmt()
.compact()
.with_max_level(if args.debug { tracing::Level::DEBUG } else { tracing::Level::INFO })
.init();
let db = sea_orm::Database::connect(args.db)
.await
.expect("could not connect to scct database");
match args.cmd {
#[cfg(feature = "migrations")]
Command::Migrate => {
use scct_migrations::MigratorTrait;
scct_migrations::Migrator::up(&db, None)
.await
.expect("could not apply scct migrations");
},
#[cfg(feature = "server")]
Command::Serve { addr } =>
scct_server::serve(&addr)
.await
.expect("scct server terminated with exception"),
}
}