use structopt::StructOpt; use std::{ boxed::Box, error::Error, }; use tokio::sync::RwLock; use crate::{ cli::Options, config::Config, }; mod cli; mod config; #[cfg(feature = "sqlite")] mod sqlite; const DEFAULT_DATABASE_PATH: &'static str = "/var/lib/noise-server/noise-server.sqlite"; #[tokio::main] async fn main() -> Result<(), Box> { let clap_matches = Options::clap().get_matches(); let options = Options::from_clap(&clap_matches); if options.generate_config { println!("{}", toml::to_string_pretty(&Config::default())?); return Ok(()); } let mut config = Config::get(&options).await?; if clap_matches.occurrences_of("database-path") > 0 { config.database_path = options.database_path.clone(); } dbg!(&config); #[cfg(feature = "sqlite")] let mut sqlite_connection = RwLock::new(sqlite::connect(&config.database_path).await?); #[cfg(feature = "sqlite")] sqlite::load_template(sqlite_connection.get_mut()).await?; Ok(()) }