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,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-29 00:40:19 +02:00
|
|
|
#[tokio::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 } =>
|
2024-08-12 19:44:38 +02:00
|
|
|
scct_server::serve(&addr, db)
|
2024-06-21 20:50:47 +02:00
|
|
|
.await
|
|
|
|
.expect("scct server terminated with exception"),
|
|
|
|
}
|
|
|
|
}
|