|
|
|
@ -29,7 +29,7 @@ pub(crate) struct Config {
|
|
|
|
|
pub(crate) hosts: HashMap<std::net::IpAddr, u64>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub(crate) fn setup_clap() -> clap::ArgMatches<'static> {
|
|
|
|
|
fn setup_clap() -> clap::ArgMatches<'static> {
|
|
|
|
|
clap_app!(myapp =>
|
|
|
|
|
(name: crate_name!())
|
|
|
|
|
(version: crate_version!())
|
|
|
|
@ -42,7 +42,7 @@ pub(crate) fn setup_clap() -> clap::ArgMatches<'static> {
|
|
|
|
|
.get_matches()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub(crate) fn setup_fern(level: u64) {
|
|
|
|
|
fn setup_fern(level: u64) {
|
|
|
|
|
let level = match level {
|
|
|
|
|
0 => log::LevelFilter::Error,
|
|
|
|
|
1 => log::LevelFilter::Warn,
|
|
|
|
@ -70,7 +70,16 @@ pub(crate) fn setup_fern(level: u64) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub(crate) fn read_config(path: &str) -> Result<Config> {
|
|
|
|
|
fn read_config(path: &str) -> Result<Config> {
|
|
|
|
|
let config_file_content = std::fs::read_to_string(path).context("Couldn't read config file")?;
|
|
|
|
|
Ok(toml::from_str(&config_file_content).context("Couldn't parse config file")?)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub(crate) fn setup_app() -> Result<Config> {
|
|
|
|
|
let clap = setup_clap();
|
|
|
|
|
setup_fern(clap.occurrences_of("v"));
|
|
|
|
|
let config_path = clap
|
|
|
|
|
.value_of("config")
|
|
|
|
|
.context("Got no config file. clap should've catched this")?;
|
|
|
|
|
Ok(read_config(config_path).context("Couldn't read config file!")?)
|
|
|
|
|
}
|
|
|
|
|