#![feature(proc_macro_hygiene, decl_macro)] #[macro_use] extern crate rocket; #[macro_use] extern crate diesel; #[macro_use] extern crate diesel_migrations; mod models; mod config; mod schema; mod routes; mod dns; mod cli; use std::process::exit; use clap::Parser; use figment::{Figment, Profile, providers::{Format, Toml, Env}}; use rocket_sync_db_pools::database; use diesel::prelude::*; use crate::cli::{NomiloCli, NomiloCommand}; #[database("sqlite")] pub struct DbConn(diesel::SqliteConnection); pub fn get_db_conn(figment: &Figment) -> diesel::SqliteConnection { let url = match figment.focus("databases.sqlite").extract_inner::("url") { Ok(url) => url, Err(e) => { eprintln!("Error loading configuration: {}", e); exit(1); } }; match diesel::SqliteConnection::establish(&url) { Ok(c) => c, Err(e) => { eprintln!("Error connecting to database at \"{}\": {}", url, e); exit(1); } } } fn main() { let figment = Figment::from(rocket::Config::default()) .merge(Toml::file(Env::var_or("NOMILO_CONFIG", "nomilo.toml")).nested()) .merge(Env::prefixed("NOMILO_").ignore(&["PROFILE"]).global()) .select(Profile::from_env_or("NOMILO_PROFILE", "release")); let app_config = match figment.extract::() { Ok(c) => c, Err(e) => { eprintln!("Error loading configuration: {}", e); exit(1); } }; let nomilo = NomiloCli::parse(); nomilo.run(figment, app_config); }