rt: Runtime::new() should return Result<>
This commit is contained in:
parent
6b2502c4d7
commit
aec1649166
1 changed files with 15 additions and 7 deletions
|
@ -1,4 +1,5 @@
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
use std::result::Result as RResult;
|
||||||
|
|
||||||
pub use clap::App;
|
pub use clap::App;
|
||||||
|
|
||||||
|
@ -7,6 +8,8 @@ use log;
|
||||||
use log::LogLevelFilter;
|
use log::LogLevelFilter;
|
||||||
|
|
||||||
use configuration::Configuration;
|
use configuration::Configuration;
|
||||||
|
use error::RuntimeError;
|
||||||
|
use error::RuntimeErrorKind;
|
||||||
use logger::ImagLogger;
|
use logger::ImagLogger;
|
||||||
|
|
||||||
use libimagstore::store::Store;
|
use libimagstore::store::Store;
|
||||||
|
@ -28,7 +31,7 @@ impl<'a> Runtime<'a> {
|
||||||
* The cli_spec object should be initially build with the ::get_default_cli_builder() function.
|
* The cli_spec object should be initially build with the ::get_default_cli_builder() function.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
pub fn new(cli_spec: App<'a, 'a, 'a, 'a, 'a, 'a>) -> Runtime<'a> {
|
pub fn new(cli_spec: App<'a, 'a, 'a, 'a, 'a, 'a>) -> Result<Runtime<'a>, RuntimeError> {
|
||||||
let matches = cli_spec.get_matches();
|
let matches = cli_spec.get_matches();
|
||||||
let rtp : PathBuf = matches.value_of("runtimepath").unwrap_or("~/.imag/").into();
|
let rtp : PathBuf = matches.value_of("runtimepath").unwrap_or("~/.imag/").into();
|
||||||
let storepath = matches.value_of("storepath")
|
let storepath = matches.value_of("storepath")
|
||||||
|
@ -38,12 +41,17 @@ impl<'a> Runtime<'a> {
|
||||||
spath.push("/store");
|
spath.push("/store");
|
||||||
spath
|
spath
|
||||||
});
|
});
|
||||||
Runtime {
|
Store::new(storepath).map(|store| {
|
||||||
cli_matches: matches,
|
Runtime {
|
||||||
configuration: Configuration::new(&rtp).unwrap_or(Configuration::default()),
|
cli_matches: matches,
|
||||||
rtp: rtp,
|
configuration: Configuration::new(&rtp).unwrap_or(Configuration::default()),
|
||||||
store: Store::new(storepath),
|
rtp: rtp,
|
||||||
}
|
store: store,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.map_err(|e| {
|
||||||
|
RuntimeError::new(RuntimeErrorKind::Instantiate, Some(Box::new(e)))
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue