Add configuration module

This commit is contained in:
Matthias Beyer 2015-10-26 22:30:15 +01:00
parent 04567f594d
commit 32e585e7eb
3 changed files with 35 additions and 0 deletions

View file

@ -15,6 +15,12 @@ args:
help: Sets the level of debugging information help: Sets the level of debugging information
required: false required: false
- rtp:
short: r
long: runtimepath
help: Set the runtime path
required: false
subcommands: subcommands:
- cal: - cal:
about: Calendar module about: Calendar module

26
src/config.rs Normal file
View file

@ -0,0 +1,26 @@
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/"))
}

View file

@ -2,10 +2,12 @@
#[macro_use] extern crate log; #[macro_use] extern crate log;
use cli::Config; use cli::Config;
use config::Configuration;
use runtime::{ImagLogger, Runtime}; use runtime::{ImagLogger, Runtime};
use clap::App; use clap::App;
mod cli; mod cli;
mod config;
mod runtime; mod runtime;
mod module; mod module;
mod storage; mod storage;
@ -15,6 +17,7 @@ fn main() {
let yaml = load_yaml!("../etc/cli.yml"); let yaml = load_yaml!("../etc/cli.yml");
let app = App::from_yaml(yaml); let app = App::from_yaml(yaml);
let mut config = Config::new(app); let mut config = Config::new(app);
let configuration = Configuration::new(&config);
let logger = ImagLogger::init(&config); let logger = ImagLogger::init(&config);
let rt = Runtime::new(config); let rt = Runtime::new(config);