2023-12-30 05:08:05 +01:00
|
|
|
pub mod model;
|
2024-03-16 03:29:06 +01:00
|
|
|
pub mod migrations;
|
2024-03-14 05:27:08 +01:00
|
|
|
pub mod activitystream;
|
2024-03-15 19:43:29 +01:00
|
|
|
pub mod server;
|
2023-12-30 05:08:05 +01:00
|
|
|
|
2024-03-16 03:29:06 +01:00
|
|
|
use clap::{Parser, Subcommand};
|
2024-03-16 05:45:58 +01:00
|
|
|
use sea_orm::{ConnectOptions, Database};
|
2024-03-16 03:29:06 +01:00
|
|
|
use sea_orm_migration::MigratorTrait;
|
|
|
|
|
|
|
|
#[derive(Parser)]
|
|
|
|
/// all names were taken
|
|
|
|
struct CliArgs {
|
|
|
|
#[clap(subcommand)]
|
|
|
|
/// command to run
|
|
|
|
command: CliCommand,
|
|
|
|
|
|
|
|
#[arg(short, long, default_value = "sqlite://./anwt.db")]
|
|
|
|
/// database connection uri
|
|
|
|
database: String,
|
|
|
|
|
|
|
|
#[arg(long, default_value_t=false)]
|
|
|
|
/// run with debug level tracing
|
|
|
|
debug: bool,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Subcommand)]
|
|
|
|
enum CliCommand {
|
|
|
|
/// run fediverse server
|
|
|
|
Serve ,
|
|
|
|
|
|
|
|
/// apply database migrations
|
|
|
|
Migrate,
|
|
|
|
}
|
2024-02-09 17:07:55 +01:00
|
|
|
|
|
|
|
#[tokio::main]
|
|
|
|
async fn main() {
|
2024-03-15 19:43:29 +01:00
|
|
|
|
2024-03-16 03:29:06 +01:00
|
|
|
let args = CliArgs::parse();
|
|
|
|
|
|
|
|
tracing_subscriber::fmt()
|
|
|
|
.compact()
|
|
|
|
.with_max_level(if args.debug { tracing::Level::DEBUG } else { tracing::Level::INFO })
|
|
|
|
.init();
|
|
|
|
|
2024-03-16 05:45:58 +01:00
|
|
|
let mut opts = ConnectOptions::new(&args.database);
|
|
|
|
opts
|
|
|
|
.max_connections(1);
|
|
|
|
|
|
|
|
let db = Database::connect(opts)
|
2024-03-16 03:29:06 +01:00
|
|
|
.await.expect("error connecting to db");
|
|
|
|
|
|
|
|
match args.command {
|
|
|
|
CliCommand::Serve => server::serve(db)
|
|
|
|
.await,
|
|
|
|
|
|
|
|
CliCommand::Migrate => migrations::Migrator::up(&db, None)
|
|
|
|
.await.expect("error applying migrations"),
|
2024-03-15 19:43:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|