Configuration is optional
This commit is contained in:
parent
21d5d32d50
commit
2fa10067fb
2 changed files with 14 additions and 8 deletions
|
@ -16,7 +16,6 @@ pub mod error {
|
||||||
*/
|
*/
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
pub enum ConfigErrorKind {
|
pub enum ConfigErrorKind {
|
||||||
ConfigNotFound,
|
|
||||||
ConfigParsingFailed,
|
ConfigParsingFailed,
|
||||||
NoConfigFileFound,
|
NoConfigFileFound,
|
||||||
}
|
}
|
||||||
|
@ -54,7 +53,6 @@ pub mod error {
|
||||||
*/
|
*/
|
||||||
pub fn as_str(e: &ConfigError) -> &'static str {
|
pub fn as_str(e: &ConfigError) -> &'static str {
|
||||||
match e.kind() {
|
match e.kind() {
|
||||||
ConfigErrorKind::ConfigNotFound => "Config not found",
|
|
||||||
ConfigErrorKind::ConfigParsingFailed => "Config parsing failed",
|
ConfigErrorKind::ConfigParsingFailed => "Config parsing failed",
|
||||||
ConfigErrorKind::NoConfigFileFound => "No config file found",
|
ConfigErrorKind::NoConfigFileFound => "No config file found",
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ use libimagstore::store::Store;
|
||||||
|
|
||||||
pub struct Runtime<'a> {
|
pub struct Runtime<'a> {
|
||||||
rtp: PathBuf,
|
rtp: PathBuf,
|
||||||
configuration: Configuration,
|
configuration: Option<Configuration>,
|
||||||
cli_matches: ArgMatches<'a>,
|
cli_matches: ArgMatches<'a>,
|
||||||
store: Store,
|
store: Store,
|
||||||
}
|
}
|
||||||
|
@ -34,6 +34,8 @@ impl<'a> Runtime<'a> {
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
|
|
||||||
|
use configuration::error::ConfigErrorKind;
|
||||||
|
|
||||||
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")
|
||||||
.map(PathBuf::from)
|
.map(PathBuf::from)
|
||||||
|
@ -54,11 +56,17 @@ impl<'a> Runtime<'a> {
|
||||||
});
|
});
|
||||||
|
|
||||||
let cfg = Configuration::new(&rtp);
|
let cfg = Configuration::new(&rtp);
|
||||||
if cfg.is_err() {
|
let cfg = if cfg.is_err() {
|
||||||
let cause : Option<Box<Error>> = Some(Box::new(cfg.err().unwrap()));
|
let e = cfg.err().unwrap();
|
||||||
return Err(RuntimeError::new(RuntimeErrorKind::Instantiate, cause));
|
if e.kind() != ConfigErrorKind::NoConfigFileFound {
|
||||||
}
|
let cause : Option<Box<Error>> = Some(Box::new(e));
|
||||||
let cfg = cfg.unwrap();
|
return Err(RuntimeError::new(RuntimeErrorKind::Instantiate, cause));
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Some(cfg.unwrap())
|
||||||
|
};
|
||||||
|
|
||||||
Store::new(storepath).map(|store| {
|
Store::new(storepath).map(|store| {
|
||||||
Runtime {
|
Runtime {
|
||||||
|
|
Loading…
Reference in a new issue