diff --git a/src/config.rs b/src/config.rs deleted file mode 100644 index 9ceea9b9..00000000 --- a/src/config.rs +++ /dev/null @@ -1,26 +0,0 @@ -extern crate clap; - -use cli::Config; - -use std::path::Path; -use clap::{App, ArgMatches}; - -pub struct Configuration { - pub rtp : String, -} - -impl Configuration { - - pub fn new(config: &Config) -> Configuration { - Configuration { - rtp: rtp_path(config), - } - } - -} - -fn rtp_path(config: &Config) -> String { - String::from(config.cli_matches.value_of("rtp").unwrap_or("~/.imag/store/")) -} - - diff --git a/src/configuration.rs b/src/configuration.rs new file mode 100644 index 00000000..3d15bcc3 --- /dev/null +++ b/src/configuration.rs @@ -0,0 +1,59 @@ +extern crate clap; + +use cli::Config; + +use std::path::Path; +use clap::{App, ArgMatches}; +use config::reader::from_file; +use config::types::Config as Cfg; +use config::types::Value as V; +use config::types::ScalarValue as S; + +pub struct Configuration { + pub rtp : String, + pub verbose : bool, + pub debugging : bool, +} + +impl Configuration { + + pub fn new(config: &Config) -> Configuration { + let rtp = rtp_path(config); + + let mut verbose = false; + let mut debugging = false; + + if let Some(cfg) = fetch_config(&rtp) { + if let Some(v) = cfg.lookup_boolean("verbose") { + verbose = v; + } + if let Some(d) = cfg.lookup_boolean("debug") { + debugging = d; + } + } + + Configuration { + verbose: verbose, + debugging: debugging, + rtp: rtp, + } + } + + pub fn is_verbose(&self) -> bool { + self.verbose + } + + pub fn is_debugging(&self) -> bool { + self.debugging + } + +} + +fn rtp_path(config: &Config) -> String { + String::from(config.cli_matches.value_of("rtp").unwrap_or("~/.imag/store/")) +} + +fn fetch_config(rtp: &String) -> Option { + from_file(Path::new(&(rtp.clone() + "/config"))).ok() +} + diff --git a/src/main.rs b/src/main.rs index 2c34de97..e447b5ac 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,13 +1,14 @@ #[macro_use] extern crate clap; #[macro_use] extern crate log; +extern crate config; use cli::Config; -use config::Configuration; +use configuration::Configuration; use runtime::{ImagLogger, Runtime}; use clap::App; mod cli; -mod config; +mod configuration; mod runtime; mod module; mod storage;