upub/src/main.rs

68 lines
1.3 KiB
Rust
Raw Normal View History

pub mod model;
pub mod migrations;
2024-03-14 05:27:08 +01:00
pub mod activitystream;
pub mod server;
use clap::{Parser, Subcommand};
use sea_orm::{ConnectOptions, Database};
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://./upub.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-03-16 05:46:14 +01:00
/// generate fake user, note and activity
Faker,
}
2024-02-09 17:07:55 +01:00
#[tokio::main]
async fn main() {
let args = CliArgs::parse();
tracing_subscriber::fmt()
.compact()
.with_max_level(if args.debug { tracing::Level::DEBUG } else { tracing::Level::INFO })
.init();
let mut opts = ConnectOptions::new(&args.database);
opts
.max_connections(1);
let db = Database::connect(opts)
.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-16 05:46:14 +01:00
CliCommand::Faker => model::faker(&db)
.await.expect("error creating fake entities"),
}
}