diff options
| author | Fuwn <[email protected]> | 2021-05-26 22:22:50 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2021-05-26 22:22:50 -0700 |
| commit | 92b9807dd02c7a17fef7e337c173bcf9379763ac (patch) | |
| tree | 26fbf87a60f72327ecd7b4e87e46271e04e884d7 /crates | |
| parent | style(whirl_api): remove singleton uses (diff) | |
| download | whirl-92b9807dd02c7a17fef7e337c173bcf9379763ac.tar.xz whirl-92b9807dd02c7a17fef7e337c173bcf9379763ac.zip | |
refactor(whirl): move whirl struct to lib
Diffstat (limited to 'crates')
| -rw-r--r-- | crates/whirl/src/lib.rs | 35 | ||||
| -rw-r--r-- | crates/whirl/src/main.rs | 2 | ||||
| -rw-r--r-- | crates/whirl/src/whirl.rs | 36 |
3 files changed, 35 insertions, 38 deletions
diff --git a/crates/whirl/src/lib.rs b/crates/whirl/src/lib.rs index 10061fd..47e0ecb 100644 --- a/crates/whirl/src/lib.rs +++ b/crates/whirl/src/lib.rs @@ -25,4 +25,37 @@ static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc; static GLOBAL: jemallocator::Jemalloc = jemallocator::Jemalloc; pub mod cli; -pub mod whirl; + +use whirl_config::Config; + +pub struct Whirl; +impl Whirl { + pub async fn splash() -> Result<(), Box<dyn std::error::Error>> { + // Environment + std::env::set_var("DATABASE_URL", "whirl.sqlite3"); + + // Logging + dotenv::dotenv().ok(); + human_panic::setup_panic!(); + if Config::get().whirlsplash.log.enable { + let logger = flexi_logger::Logger::with_str(whirl_common::log::calculate_log_level()); + if std::env::var("LOG_FILE").unwrap_or_else(|_| "true".to_string()) == "false" + || !whirl_config::Config::get().whirlsplash.log.file + || std::env::args().collect::<Vec<_>>()[1] == "clean" + // Cheeky as all hell. + { + logger.start()?; + } else { + logger + .print_message() + .log_to_file() + .directory("log") + .start()?; + } + } + + crate::cli::Cli::execute().await.unwrap(); + + Ok(()) + } +} diff --git a/crates/whirl/src/main.rs b/crates/whirl/src/main.rs index 8aa7ceb..dabc574 100644 --- a/crates/whirl/src/main.rs +++ b/crates/whirl/src/main.rs @@ -2,4 +2,4 @@ // SPDX-License-Identifier: GPL-3.0-only #[tokio::main] -async fn main() -> Result<(), Box<dyn std::error::Error>> { whirl::whirl::Whirl::splash().await } +async fn main() -> Result<(), Box<dyn std::error::Error>> { whirl::Whirl::splash().await } diff --git a/crates/whirl/src/whirl.rs b/crates/whirl/src/whirl.rs deleted file mode 100644 index f422c4f..0000000 --- a/crates/whirl/src/whirl.rs +++ /dev/null @@ -1,36 +0,0 @@ -// Copyleft (ɔ) 2021-2021 The Whirlsplash Collective -// SPDX-License-Identifier: GPL-3.0-only - -use whirl_config::Config; - -pub struct Whirl; -impl Whirl { - pub async fn splash() -> Result<(), Box<dyn std::error::Error>> { - // Environment - std::env::set_var("DATABASE_URL", "whirl.sqlite3"); - - // Logging - dotenv::dotenv().ok(); - human_panic::setup_panic!(); - if Config::get().whirlsplash.log.enable { - let logger = flexi_logger::Logger::with_str(whirl_common::log::calculate_log_level()); - if std::env::var("LOG_FILE").unwrap_or_else(|_| "true".to_string()) == "false" - || !whirl_config::Config::get().whirlsplash.log.file - || std::env::args().collect::<Vec<_>>()[1] == "clean" - // Cheeky as all hell. - { - logger.start()?; - } else { - logger - .print_message() - .log_to_file() - .directory("log") - .start()?; - } - } - - crate::cli::Cli::execute().await.unwrap(); - - Ok(()) - } -} |