From 9f4577f0edd38e3feac6b724abdb59b0a2d06900 Mon Sep 17 00:00:00 2001 From: Edward Shen Date: Mon, 23 Dec 2019 22:59:12 -0500 Subject: [PATCH] actually name yaml file correctly --- bunbun.default.toml => bunbun.default.yaml | 4 ++ src/main.rs | 46 +++++++++++++--------- 2 files changed, 32 insertions(+), 18 deletions(-) rename bunbun.default.toml => bunbun.default.yaml (97%) diff --git a/bunbun.default.toml b/bunbun.default.yaml similarity index 97% rename from bunbun.default.toml rename to bunbun.default.yaml index b3d21ce..b63ac8e 100644 --- a/bunbun.default.toml +++ b/bunbun.default.yaml @@ -10,6 +10,10 @@ public_address: "localhost:8080" default_route: "g" routes: + +groups: + meta: + # Meta ls: "/ls" help: "/ls" diff --git a/src/main.rs b/src/main.rs index 81d5a78..c423e38 100644 --- a/src/main.rs +++ b/src/main.rs @@ -17,7 +17,7 @@ use std::time::Duration; mod routes; mod template_args; -const DEFAULT_CONFIG: &[u8] = include_bytes!("../bunbun.default.toml"); +const DEFAULT_CONFIG: &[u8] = include_bytes!("../bunbun.default.yaml"); #[derive(Debug)] #[allow(clippy::enum_variant_names)] @@ -72,23 +72,12 @@ fn main() -> Result<(), BunBunError> { .author(crate_authors!()) .get_matches(); - let log_level = match min(matches.occurrences_of("verbose"), 3) as i8 - - min(matches.occurrences_of("quiet"), 2) as i8 - { - -2 => None, - -1 => Some(log::Level::Error), - 0 => Some(log::Level::Warn), - 1 => Some(log::Level::Info), - 2 => Some(log::Level::Debug), - 3 => Some(log::Level::Trace), - _ => unreachable!(), - }; + init_logger( + matches.occurrences_of("verbose"), + matches.occurrences_of("quiet"), + )?; - if let Some(level) = log_level { - simple_logger::init_with_level(level)?; - } - - // config has default location provided + // config has default location provided, unwrapping is fine. let conf_file_location = String::from(matches.value_of("config").unwrap()); let conf = read_config(&conf_file_location)?; let renderer = compile_templates(); @@ -110,7 +99,6 @@ fn main() -> Result<(), BunBunError> { let mut watch = Hotwatch::new_with_custom_delay(Duration::from_millis(500))?; // TODO: keep retry watching in separate thread - // Closures need their own copy of variables for proper lifecycle management let state_ref = state.clone(); let conf_file_location_clone = conf_file_location.clone(); @@ -156,6 +144,28 @@ fn main() -> Result<(), BunBunError> { Ok(()) } +fn init_logger( + num_verbose_flags: u64, + num_quiet_flags: u64, +) -> Result<(), BunBunError> { + let log_level = + match min(num_verbose_flags, 3) as i8 - min(num_quiet_flags, 2) as i8 { + -2 => None, + -1 => Some(log::Level::Error), + 0 => Some(log::Level::Warn), + 1 => Some(log::Level::Info), + 2 => Some(log::Level::Debug), + 3 => Some(log::Level::Trace), + _ => unreachable!(), // values are clamped to [0, 3] - [0, 2] + }; + + if let Some(level) = log_level { + simple_logger::init_with_level(level)?; + } + + Ok(()) +} + #[derive(Deserialize)] struct Config { bind_address: String,