2025-06-11 22:46:58 -04:00
|
|
|
use anyhow::Result;
|
2025-06-13 18:38:31 -04:00
|
|
|
use clap::Parser;
|
2022-07-17 17:04:48 -04:00
|
|
|
|
2025-06-13 18:38:31 -04:00
|
|
|
mod cli;
|
2025-06-11 22:46:58 -04:00
|
|
|
mod db;
|
|
|
|
|
mod logging;
|
|
|
|
|
mod places;
|
|
|
|
|
mod server;
|
2025-06-13 18:38:31 -04:00
|
|
|
mod tui;
|
2022-07-17 17:04:48 -04:00
|
|
|
|
2023-04-01 23:16:36 -04:00
|
|
|
#[tokio::main]
|
2023-08-04 23:46:34 -04:00
|
|
|
async fn main() -> Result<()> {
|
2023-04-01 23:16:36 -04:00
|
|
|
dotenvy::dotenv().unwrap_or_default();
|
2025-06-11 22:46:58 -04:00
|
|
|
logging::setup()?;
|
2023-04-01 23:16:36 -04:00
|
|
|
|
2025-06-13 18:38:31 -04:00
|
|
|
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<()> {
|
2025-06-11 22:46:58 -04:00
|
|
|
let pool = db::pool().await?;
|
|
|
|
|
db::run_migrations(&pool).await?;
|
2023-04-01 23:16:36 -04:00
|
|
|
|
2025-06-11 22:46:58 -04:00
|
|
|
let places_repository = places::db_repository::DbPlacesRepository::new(pool);
|
|
|
|
|
let places_routes = places::routes::places_routes(places_repository);
|
2023-04-01 23:16:36 -04:00
|
|
|
|
2025-06-11 22:46:58 -04:00
|
|
|
server::serve(places_routes).await?;
|
2025-06-13 18:38:31 -04:00
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async fn tui_mode() -> Result<()> {
|
|
|
|
|
let pool = db::pool().await?;
|
|
|
|
|
let places_repository = places::db_repository::DbPlacesRepository::new(pool);
|
2023-08-04 23:46:34 -04:00
|
|
|
|
2025-06-13 18:38:31 -04:00
|
|
|
tui::tui(places_repository).await?;
|
2023-08-04 23:46:34 -04:00
|
|
|
Ok(())
|
2023-04-01 23:16:36 -04:00
|
|
|
}
|