aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFuwn <[email protected]>2021-05-20 11:42:19 -0700
committerFuwn <[email protected]>2021-05-20 11:42:19 -0700
commiteab7bf98575732dff72271f9ea564336ab75cd06 (patch)
tree451a8f8c9987ca89cb4d790e6c622ef5577acf6c
parentbuild(make): checkf and checkfc tasks now run once, not on all workspaces (diff)
downloadwhirl-eab7bf98575732dff72271f9ea564336ab75cd06.tar.xz
whirl-eab7bf98575732dff72271f9ea564336ab75cd06.zip
refactor(whirl): move all of the main file's doings to a new file
It looks better, I don't ever like main file polution.
-rw-r--r--whirl/src/lib.rs1
-rw-r--r--whirl/src/main.rs31
-rw-r--r--whirl/src/whirl.rs36
3 files changed, 39 insertions, 29 deletions
diff --git a/whirl/src/lib.rs b/whirl/src/lib.rs
index c9329f3..5c7da0b 100644
--- a/whirl/src/lib.rs
+++ b/whirl/src/lib.rs
@@ -30,6 +30,7 @@ static GLOBAL: jemallocator::Jemalloc = jemallocator::Jemalloc;
pub mod cli;
pub mod subs;
+pub mod whirl;
pub mod api;
pub mod db;
diff --git a/whirl/src/main.rs b/whirl/src/main.rs
index a6d4533..074ca69 100644
--- a/whirl/src/main.rs
+++ b/whirl/src/main.rs
@@ -3,34 +3,7 @@
use std::error::Error;
-use whirl::{cli::Cli, utils::log::calculate_log_level};
-use whirl_config::Config;
+use whirl::whirl::Whirl;
#[tokio::main]
-async fn main() -> Result<(), Box<dyn Error>> {
- // Environment
- let matches = Cli::setup();
-
- // Logging
- dotenv::dotenv().ok();
- human_panic::setup_panic!();
- let logger = flexi_logger::Logger::with_str(calculate_log_level());
- if std::env::var("LOG_FILE").unwrap_or_else(|_| "true".to_string()) == "false"
- || !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()?;
- }
-
- // Execution
- Cli::execute(matches).await.unwrap();
-
- Ok(())
-}
+async fn main() -> Result<(), Box<dyn Error>> { Whirl::splash().await }
diff --git a/whirl/src/whirl.rs b/whirl/src/whirl.rs
new file mode 100644
index 0000000..88772f6
--- /dev/null
+++ b/whirl/src/whirl.rs
@@ -0,0 +1,36 @@
+// Copyleft (ɔ) 2021-2021 The Whirlsplash Collective
+// SPDX-License-Identifier: GPL-3.0-only
+
+use std::error::Error;
+
+use crate::{cli::Cli, utils::log::calculate_log_level};
+
+pub struct Whirl;
+impl Whirl {
+ pub async fn splash() -> Result<(), Box<dyn Error>> {
+ // Environment and CLI
+ let matches = Cli::setup();
+
+ // Logging
+ dotenv::dotenv().ok();
+ human_panic::setup_panic!();
+ let logger = flexi_logger::Logger::with_str(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()?;
+ }
+
+ Cli::execute(matches).await.unwrap();
+
+ Ok(())
+ }
+}