43 lines
925 B
Rust
43 lines
925 B
Rust
use anyhow::Result;
|
|
use clap::Parser;
|
|
|
|
mod cli;
|
|
mod db;
|
|
mod logging;
|
|
mod places;
|
|
mod server;
|
|
mod tui;
|
|
|
|
#[tokio::main]
|
|
async fn main() -> Result<()> {
|
|
dotenvy::dotenv().unwrap_or_default();
|
|
logging::setup()?;
|
|
|
|
let args = cli::CliArgs::parse();
|
|
|
|
match args.mode {
|
|
cli::Mode::Server => server_mode().await?,
|
|
cli::Mode::Tui => tui_mode().await?,
|
|
}
|
|
|
|
Ok(())
|
|
}
|
|
|
|
async fn server_mode() -> Result<()> {
|
|
let pool = db::pool().await?;
|
|
db::run_migrations(&pool).await?;
|
|
|
|
let places_repository = places::db_repository::DbPlacesRepository::new(pool);
|
|
let places_routes = places::routes::places_routes(places_repository);
|
|
|
|
server::serve(places_routes).await?;
|
|
Ok(())
|
|
}
|
|
|
|
async fn tui_mode() -> Result<()> {
|
|
let pool = db::pool().await?;
|
|
let places_repository = places::db_repository::DbPlacesRepository::new(pool);
|
|
|
|
tui::tui(places_repository).await?;
|
|
Ok(())
|
|
}
|