summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2016-04-22 17:27:44 +0200
committerMatthias Beyer <mail@beyermatthias.de>2016-06-04 15:34:02 +0200
commitef86c5e1ffbd8fb01c4c638d0da18256c2920391 (patch)
tree6ff884a34357aee636d63ca95d81e7c1938ebcfe
parent0363a6a4d41ece736da473e60c33e458b83e197d (diff)
downloadimag-ef86c5e1ffbd8fb01c4c638d0da18256c2920391.zip
imag-ef86c5e1ffbd8fb01c4c638d0da18256c2920391.tar.gz
Add config module
-rw-r--r--libimagdiary/src/config.rs19
-rw-r--r--libimagdiary/src/lib.rs1
2 files changed, 20 insertions, 0 deletions
diff --git a/libimagdiary/src/config.rs b/libimagdiary/src/config.rs
new file mode 100644
index 0000000..9374928
--- /dev/null
+++ b/libimagdiary/src/config.rs
@@ -0,0 +1,19 @@
+use toml::Value;
+
+use libimagrt::runtime::Runtime;
+
+pub fn get_default_diary_name(rt: &Runtime) -> Option<String> {
+ get_diary_config_section(rt)
+ .and_then(|config| {
+ match config.lookup("default_diary") {
+ Some(&Value::String(ref s)) => Some(s.clone()),
+ _ => None,
+ }
+ })
+}
+
+pub fn get_diary_config_section<'a>(rt: &'a Runtime) -> Option<&'a Value> {
+ rt.config()
+ .map(|config| config.config())
+ .and_then(|config| config.lookup("diary"))
+}
diff --git a/libimagdiary/src/lib.rs b/libimagdiary/src/lib.rs
index 5f4567e..0e6256e 100644
--- a/libimagdiary/src/lib.rs
+++ b/libimagdiary/src/lib.rs
@@ -13,6 +13,7 @@ extern crate libimagrt;
module_entry_path_mod!("diary", "0.1.0");
+pub mod config;
pub mod error;
pub mod diaryid;
pub mod diary;