Configuration: Provide config() getter, remove the default() implementation therefor
This commit is contained in:
parent
192b3b5885
commit
21d5d32d50
2 changed files with 20 additions and 17 deletions
|
@ -1,4 +1,3 @@
|
||||||
use std::default::Default;
|
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::result::Result as RResult;
|
use std::result::Result as RResult;
|
||||||
|
|
||||||
|
@ -103,6 +102,11 @@ pub type Result<T> = RResult<T, ConfigError>;
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Configuration {
|
pub struct Configuration {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The plain configuration object for direct access if necessary
|
||||||
|
*/
|
||||||
|
config: Value,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The verbosity the program should run with
|
* The verbosity the program should run with
|
||||||
*/
|
*/
|
||||||
|
@ -142,6 +146,7 @@ impl Configuration {
|
||||||
debug!(" - editor-opts: {}", editor_opts);
|
debug!(" - editor-opts: {}", editor_opts);
|
||||||
|
|
||||||
Configuration {
|
Configuration {
|
||||||
|
config: cfg,
|
||||||
verbosity: verbosity,
|
verbosity: verbosity,
|
||||||
editor: editor,
|
editor: editor,
|
||||||
editor_opts: editor_opts,
|
editor_opts: editor_opts,
|
||||||
|
@ -149,6 +154,10 @@ impl Configuration {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn config(&self) -> &Value {
|
||||||
|
&self.config
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_verbosity(v: &Value) -> bool {
|
fn get_verbosity(v: &Value) -> bool {
|
||||||
|
@ -228,18 +237,3 @@ fn fetch_config(rtp: &PathBuf) -> Result<Value> {
|
||||||
.ok_or(ConfigError::new(ConfigErrorKind::NoConfigFileFound, None))
|
.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(""),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,7 @@ impl<'a> Runtime<'a> {
|
||||||
*/
|
*/
|
||||||
pub fn new(cli_spec: App<'a, 'a>) -> Result<Runtime<'a>, RuntimeError> {
|
pub fn new(cli_spec: App<'a, 'a>) -> Result<Runtime<'a>, RuntimeError> {
|
||||||
use std::env;
|
use std::env;
|
||||||
|
use std::error::Error;
|
||||||
|
|
||||||
let matches = cli_spec.get_matches();
|
let matches = cli_spec.get_matches();
|
||||||
let rtp : PathBuf = matches.value_of("runtimepath")
|
let rtp : PathBuf = matches.value_of("runtimepath")
|
||||||
|
@ -51,10 +52,18 @@ impl<'a> Runtime<'a> {
|
||||||
spath.push("store");
|
spath.push("store");
|
||||||
spath
|
spath
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let cfg = Configuration::new(&rtp);
|
||||||
|
if cfg.is_err() {
|
||||||
|
let cause : Option<Box<Error>> = Some(Box::new(cfg.err().unwrap()));
|
||||||
|
return Err(RuntimeError::new(RuntimeErrorKind::Instantiate, cause));
|
||||||
|
}
|
||||||
|
let cfg = cfg.unwrap();
|
||||||
|
|
||||||
Store::new(storepath).map(|store| {
|
Store::new(storepath).map(|store| {
|
||||||
Runtime {
|
Runtime {
|
||||||
cli_matches: matches,
|
cli_matches: matches,
|
||||||
configuration: Configuration::new(&rtp).unwrap_or(Configuration::default()),
|
configuration: cfg,
|
||||||
rtp: rtp,
|
rtp: rtp,
|
||||||
store: store,
|
store: store,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue