actually name yaml file correctly
This commit is contained in:
parent
f70154e819
commit
9f4577f0ed
2 changed files with 32 additions and 18 deletions
|
@ -10,6 +10,10 @@ public_address: "localhost:8080"
|
||||||
default_route: "g"
|
default_route: "g"
|
||||||
|
|
||||||
routes:
|
routes:
|
||||||
|
|
||||||
|
groups:
|
||||||
|
meta:
|
||||||
|
|
||||||
# Meta
|
# Meta
|
||||||
ls: "/ls"
|
ls: "/ls"
|
||||||
help: "/ls"
|
help: "/ls"
|
46
src/main.rs
46
src/main.rs
|
@ -17,7 +17,7 @@ use std::time::Duration;
|
||||||
mod routes;
|
mod routes;
|
||||||
mod template_args;
|
mod template_args;
|
||||||
|
|
||||||
const DEFAULT_CONFIG: &[u8] = include_bytes!("../bunbun.default.toml");
|
const DEFAULT_CONFIG: &[u8] = include_bytes!("../bunbun.default.yaml");
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
#[allow(clippy::enum_variant_names)]
|
#[allow(clippy::enum_variant_names)]
|
||||||
|
@ -72,23 +72,12 @@ fn main() -> Result<(), BunBunError> {
|
||||||
.author(crate_authors!())
|
.author(crate_authors!())
|
||||||
.get_matches();
|
.get_matches();
|
||||||
|
|
||||||
let log_level = match min(matches.occurrences_of("verbose"), 3) as i8
|
init_logger(
|
||||||
- min(matches.occurrences_of("quiet"), 2) as i8
|
matches.occurrences_of("verbose"),
|
||||||
{
|
matches.occurrences_of("quiet"),
|
||||||
-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!(),
|
|
||||||
};
|
|
||||||
|
|
||||||
if let Some(level) = log_level {
|
// config has default location provided, unwrapping is fine.
|
||||||
simple_logger::init_with_level(level)?;
|
|
||||||
}
|
|
||||||
|
|
||||||
// config has default location provided
|
|
||||||
let conf_file_location = String::from(matches.value_of("config").unwrap());
|
let conf_file_location = String::from(matches.value_of("config").unwrap());
|
||||||
let conf = read_config(&conf_file_location)?;
|
let conf = read_config(&conf_file_location)?;
|
||||||
let renderer = compile_templates();
|
let renderer = compile_templates();
|
||||||
|
@ -110,7 +99,6 @@ fn main() -> Result<(), BunBunError> {
|
||||||
|
|
||||||
let mut watch = Hotwatch::new_with_custom_delay(Duration::from_millis(500))?;
|
let mut watch = Hotwatch::new_with_custom_delay(Duration::from_millis(500))?;
|
||||||
// TODO: keep retry watching in separate thread
|
// TODO: keep retry watching in separate thread
|
||||||
|
|
||||||
// Closures need their own copy of variables for proper lifecycle management
|
// Closures need their own copy of variables for proper lifecycle management
|
||||||
let state_ref = state.clone();
|
let state_ref = state.clone();
|
||||||
let conf_file_location_clone = conf_file_location.clone();
|
let conf_file_location_clone = conf_file_location.clone();
|
||||||
|
@ -156,6 +144,28 @@ fn main() -> Result<(), BunBunError> {
|
||||||
Ok(())
|
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)]
|
#[derive(Deserialize)]
|
||||||
struct Config {
|
struct Config {
|
||||||
bind_address: String,
|
bind_address: String,
|
||||||
|
|
Loading…
Reference in a new issue