From 21d5d32d50de52b34f56ab58f384b866ade7537a Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sat, 5 Mar 2016 12:36:11 +0100 Subject: [PATCH] Configuration: Provide config() getter, remove the default() implementation therefor --- libimagrt/src/configuration.rs | 26 ++++++++++---------------- libimagrt/src/runtime.rs | 11 ++++++++++- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/libimagrt/src/configuration.rs b/libimagrt/src/configuration.rs index e46da970..7eb8e30f 100644 --- a/libimagrt/src/configuration.rs +++ b/libimagrt/src/configuration.rs @@ -1,4 +1,3 @@ -use std::default::Default; use std::path::PathBuf; use std::result::Result as RResult; @@ -103,6 +102,11 @@ pub type Result = RResult; #[derive(Debug)] pub struct Configuration { + /** + * The plain configuration object for direct access if necessary + */ + config: Value, + /** * The verbosity the program should run with */ @@ -142,6 +146,7 @@ impl Configuration { debug!(" - editor-opts: {}", editor_opts); Configuration { + config: cfg, verbosity: verbosity, editor: editor, editor_opts: editor_opts, @@ -149,6 +154,10 @@ impl Configuration { }) } + pub fn config(&self) -> &Value { + &self.config + } + } fn get_verbosity(v: &Value) -> bool { @@ -228,18 +237,3 @@ fn fetch_config(rtp: &PathBuf) -> Result { .ok_or(ConfigError::new(ConfigErrorKind::NoConfigFileFound, None)) } -impl Default for Configuration { - - /** - * Get a default configuration object - */ - fn default() -> Configuration { - Configuration { - verbosity: false, - editor: Some(String::from("nano")), - editor_opts: String::from(""), - } - } - -} - diff --git a/libimagrt/src/runtime.rs b/libimagrt/src/runtime.rs index 23383b1d..c5b7412f 100644 --- a/libimagrt/src/runtime.rs +++ b/libimagrt/src/runtime.rs @@ -32,6 +32,7 @@ impl<'a> Runtime<'a> { */ pub fn new(cli_spec: App<'a, 'a>) -> Result, RuntimeError> { use std::env; + use std::error::Error; let matches = cli_spec.get_matches(); let rtp : PathBuf = matches.value_of("runtimepath") @@ -51,10 +52,18 @@ impl<'a> Runtime<'a> { spath.push("store"); spath }); + + let cfg = Configuration::new(&rtp); + if cfg.is_err() { + let cause : Option> = Some(Box::new(cfg.err().unwrap())); + return Err(RuntimeError::new(RuntimeErrorKind::Instantiate, cause)); + } + let cfg = cfg.unwrap(); + Store::new(storepath).map(|store| { Runtime { cli_matches: matches, - configuration: Configuration::new(&rtp).unwrap_or(Configuration::default()), + configuration: cfg, rtp: rtp, store: store, }