configuration.rs: Add possibility to fetch editor

This commit is contained in:
Matthias Beyer 2015-12-30 02:40:38 +01:00
parent 808e44339a
commit 89878f7024

View file

@ -10,6 +10,7 @@ pub struct Configuration {
pub store_sub : String, pub store_sub : String,
pub verbose : bool, pub verbose : bool,
pub debugging : bool, pub debugging : bool,
pub editor : Option<String>,
} }
impl Configuration { impl Configuration {
@ -20,6 +21,7 @@ impl Configuration {
let mut verbose = false; let mut verbose = false;
let mut debugging = false; let mut debugging = false;
let mut store_sub = String::from("/store"); let mut store_sub = String::from("/store");
let mut editor = None;
if let Some(cfg) = fetch_config(rtp.clone()) { if let Some(cfg) = fetch_config(rtp.clone()) {
if let Some(v) = cfg.lookup_boolean("verbose") { if let Some(v) = cfg.lookup_boolean("verbose") {
@ -31,6 +33,9 @@ impl Configuration {
if let Some(s) = cfg.lookup_str("store") { if let Some(s) = cfg.lookup_str("store") {
store_sub = String::from(s); store_sub = String::from(s);
} }
if let Some(s) = cfg.lookup_str("editor") {
editor = Some(String::from(s));
}
} }
let runtimepath = rtp.unwrap_or(String::from("/tmp/")); let runtimepath = rtp.unwrap_or(String::from("/tmp/"));
@ -40,12 +45,14 @@ impl Configuration {
debug!(" - debugging : {}", debugging); debug!(" - debugging : {}", debugging);
debug!(" - store sub : {}", store_sub); debug!(" - store sub : {}", store_sub);
debug!(" - runtimepath: {}", runtimepath); debug!(" - runtimepath: {}", runtimepath);
debug!(" - editor : {}", editor.unwrap_or(String::from("")));
Configuration { Configuration {
verbose: verbose, verbose: verbose,
debugging: debugging, debugging: debugging,
store_sub: store_sub, store_sub: store_sub,
rtp: runtimepath, rtp: runtimepath,
editor: editor,
} }
} }
@ -65,6 +72,10 @@ impl Configuration {
self.rtp.clone() self.rtp.clone()
} }
pub fn editor(&self) -> Option<String> {
self.editor
}
} }
fn rtp_path(config: &CliConfig) -> Option<String> { fn rtp_path(config: &CliConfig) -> Option<String> {