summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2017-07-13 20:06:28 +0200
committerGitHub <noreply@github.com>2017-07-13 20:06:28 +0200
commitafc5d1f929a49c72e76dd0140570e21a982817a6 (patch)
tree1559a0031cd23ceb28521d5261068758a2a8b5e3
parentbee4e0642689deb563dd92d02e2b211647db6a6d (diff)
parent398332fcb240846169b15ccaab6e4d3c33fac5f8 (diff)
downloadimag-afc5d1f929a49c72e76dd0140570e21a982817a6.zip
imag-afc5d1f929a49c72e76dd0140570e21a982817a6.tar.gz
Merge pull request #995 from matthiasbeyer/update-toml-query
Update toml query
-rw-r--r--imag-todo/Cargo.toml2
-rw-r--r--imag-todo/src/main.rs8
-rw-r--r--libimagcounter/Cargo.toml2
-rw-r--r--libimagcounter/src/counter.rs21
-rw-r--r--libimagdiary/Cargo.toml2
-rw-r--r--libimagdiary/src/config.rs7
-rw-r--r--libimagentrycategory/Cargo.toml2
-rw-r--r--libimagentrycategory/src/category.rs15
-rw-r--r--libimagentrycategory/src/register.rs11
-rw-r--r--libimagentrydatetime/Cargo.toml2
-rw-r--r--libimagentrydatetime/src/datetime.rs23
-rw-r--r--libimagtimetrack/Cargo.toml2
-rw-r--r--libimagtimetrack/src/event.rs17
-rw-r--r--libimagtodo/Cargo.toml2
14 files changed, 66 insertions, 50 deletions
diff --git a/imag-todo/Cargo.toml b/imag-todo/Cargo.toml
index 9a32ce4..bc11fc5 100644
--- a/imag-todo/Cargo.toml
+++ b/imag-todo/Cargo.toml
@@ -21,7 +21,7 @@ semver = "0.5.1"
serde_json = "0.8.3"
task-hookrs = "0.2.2"
toml = "0.4.*"
-toml-query = "0.2.*"
+toml-query = "0.3.*"
is-match = "0.1.*"
version = "2.0.1"
diff --git a/imag-todo/src/main.rs b/imag-todo/src/main.rs
index 4d6396b..b9bd887 100644
--- a/imag-todo/src/main.rs
+++ b/imag-todo/src/main.rs
@@ -103,11 +103,15 @@ fn list(rt: &Runtime) {
// filter out the ones were we can read the uuid
let uuids : Vec<_> = iter.filter_map(|t| match t {
Ok(v) => match v.get_header().read(&String::from("todo.uuid")) {
- Ok(&Value::String(ref u)) => Some(u.clone()),
- Ok(_) => {
+ Ok(Some(&Value::String(ref u))) => Some(u.clone()),
+ Ok(Some(_)) => {
warn!("Header type error");
None
},
+ Ok(None) => {
+ warn!("Header missing field");
+ None
+ },
Err(e) => {
if !no_identifier(&e) {
trace_error(&e);
diff --git a/libimagcounter/Cargo.toml b/libimagcounter/Cargo.toml
index 4298a93..3f1f52c 100644
--- a/libimagcounter/Cargo.toml
+++ b/libimagcounter/Cargo.toml
@@ -16,7 +16,7 @@ homepage = "http://imag-pim.org"
[dependencies]
log = "0.3"
toml = "0.4.*"
-toml-query = "0.2.*"
+toml-query = "0.3.*"
semver = "0.5"
[dependencies.libimagstore]
diff --git a/libimagcounter/src/counter.rs b/libimagcounter/src/counter.rs
index 9c69901..7b6c1d3 100644
--- a/libimagcounter/src/counter.rs
+++ b/libimagcounter/src/counter.rs
@@ -117,7 +117,7 @@ impl<'a> Counter<'a> {
let mut header = self.fle.deref_mut().get_header_mut();
let query = String::from("counter.value");
match try!(header.read(&query).map_err_into(CEK::StoreReadError)) {
- &Value::Integer(i) => {
+ Some(&Value::Integer(i)) => {
header.set(&query, Value::Integer(i + 1))
.map_err_into(CEK::StoreWriteError)
.map(|_| ())
@@ -130,7 +130,7 @@ impl<'a> Counter<'a> {
let mut header = self.fle.deref_mut().get_header_mut();
let query = String::from("counter.value");
match try!(header.read(&query).map_err_into(CEK::StoreReadError)) {
- &Value::Integer(i) => {
+ Some(&Value::Integer(i)) => {
header.set(&query, Value::Integer(i - 1))
.map_err_into(CEK::StoreWriteError)
.map(|_| ())
@@ -152,15 +152,17 @@ impl<'a> Counter<'a> {
pub fn name(&self) -> Result<CounterName> {
self.read_header_at("counter.name", |v| match v {
- &Value::String(ref s) => Ok(s.clone()),
- _ => Err(CEK::HeaderTypeError.into_error()),
+ Some(&Value::String(ref s)) => Ok(s.clone()),
+ Some(_) => Err(CEK::HeaderTypeError.into_error()),
+ _ => Err(CEK::StoreReadError.into_error()),
})
}
pub fn value(&self) -> Result<i64> {
self.read_header_at("counter.value", |v| match v {
- &Value::Integer(i) => Ok(i),
- _ => Err(CEK::HeaderTypeError.into_error()),
+ Some(&Value::Integer(i)) => Ok(i),
+ Some(_) => Err(CEK::HeaderTypeError.into_error()),
+ _ => Err(CEK::StoreReadError.into_error()),
})
}
@@ -170,13 +172,14 @@ impl<'a> Counter<'a> {
pub fn read_unit(&self) -> Result<Option<CounterUnit>> {
self.read_header_at("counter.unit", |s| match s {
- &Value::String(ref s) => Ok(Some(CounterUnit::new(s.clone()))),
- _ => Err(CEK::HeaderTypeError.into_error()),
+ Some(&Value::String(ref s)) => Ok(Some(CounterUnit::new(s.clone()))),
+ Some(_) => Err(CEK::HeaderTypeError.into_error()),
+ _ => Err(CEK::StoreReadError.into_error()),
})
}
fn read_header_at<T, F>(&self, name: &str, f: F) -> Result<T>
- where F: FnOnce(&Value) -> Result<T>
+ where F: FnOnce(Option<&Value>) -> Result<T>
{
self.fle
diff --git a/libimagdiary/Cargo.toml b/libimagdiary/Cargo.toml
index 0f89195..751530f 100644
--- a/libimagdiary/Cargo.toml
+++ b/libimagdiary/Cargo.toml
@@ -18,7 +18,7 @@ chrono = "0.2"
log = "0.3"
semver = "0.5"
toml = "0.4.*"
-toml-query = "0.2.*"
+toml-query = "0.3.*"
regex = "0.1"
itertools = "0.5"
diff --git a/libimagdiary/src/config.rs b/libimagdiary/src/config.rs
index a341b24..c2a6a98 100644
--- a/libimagdiary/src/config.rs
+++ b/libimagdiary/src/config.rs
@@ -27,7 +27,7 @@ pub fn get_default_diary_name(rt: &Runtime) -> Option<String> {
get_diary_config_section(rt)
.and_then(|config| {
match config.read(&String::from("default_diary")) {
- Ok(&Value::String(ref s)) => Some(s.clone()),
+ Ok(Some(&Value::String(ref s))) => Some(s.clone()),
_ => None,
}
})
@@ -36,5 +36,8 @@ pub fn get_default_diary_name(rt: &Runtime) -> Option<String> {
pub fn get_diary_config_section<'a>(rt: &'a Runtime) -> Option<&'a Value> {
rt.config()
.map(|config| config.config())
- .and_then(|config| config.read(&String::from("diary")).ok())
+ .and_then(|config| match config.read(&String::from("diary")) {
+ Ok(x) => x,
+ Err(_) => None,
+ })
}
diff --git a/libimagentrycategory/Cargo.toml b/libimagentrycategory/Cargo.toml
index 36035cf..8e99644 100644
--- a/libimagentrycategory/Cargo.toml
+++ b/libimagentrycategory/Cargo.toml
@@ -16,7 +16,7 @@ homepage = "http://imag-pim.org"
[dependencies]
log = "0.3"
toml = "0.4"
-toml-query = "0.2"
+toml-query = "0.3"
is-match = "0.1"
[dev-dependencies]
diff --git a/libimagentrycategory/src/category.rs b/libimagentrycategory/src/category.rs
index 8976391..1e77495 100644
--- a/libimagentrycategory/src/category.rs
+++ b/libimagentrycategory/src/category.rs
@@ -88,23 +88,16 @@ impl EntryCategory for Entry {
}
.map_err_into(CEK::HeaderReadError),
- Ok(&Value::String(ref s)) => Ok(Some(s.clone().into())),
+ Ok(Some(&Value::String(ref s))) => Ok(Some(s.clone().into())),
+ Ok(None) => Err(CEK::StoreReadError.into_error()).map_err_into(CEK::HeaderReadError),
Ok(_) => Err(CEK::TypeError.into_error()).map_err_into(CEK::HeaderReadError),
}
}
fn has_category(&self) -> Result<bool> {
- let res = self.get_header().read(&String::from("category.value"));
- if res.is_err() {
- let res = res.unwrap_err();
- match res.kind() {
- &TQEK::IdentifierNotFoundInDocument(_) => Ok(false),
- _ => Err(res),
- }
+ self.get_header().read(&String::from("category.value"))
.map_err_into(CEK::HeaderReadError)
- } else {
- Ok(true)
- }
+ .map(|e| e.is_some())
}
}
diff --git a/libimagentrycategory/src/register.rs b/libimagentrycategory/src/register.rs
index aa85d80..e885363 100644
--- a/libimagentrycategory/src/register.rs
+++ b/libimagentrycategory/src/register.rs
@@ -198,9 +198,10 @@ mod tests {
assert!(header_field.is_ok(), format!("Expected Ok(_), got: {:?}", header_field));
let header_field = header_field.unwrap();
- match *header_field {
- Value::String(ref s) => assert_eq!(category_name, s),
- _ => assert!(false, "Header field has wrong type"),
+ match header_field {
+ Some(&Value::String(ref s)) => assert_eq!(category_name, s),
+ Some(_) => assert!(false, "Header field has wrong type"),
+ None => assert!(false, "Header field not present"),
}
}
}
@@ -228,7 +229,7 @@ fn represents_category(store: &Store, sid: StoreId, name: &str) -> Result<bool>
.read(&String::from(CATEGORY_REGISTER_NAME_FIELD_PATH))
.map_err_into(CEK::HeaderReadError)
{
- Ok(&Value::String(ref s)) => Ok(s == name),
+ Ok(Some(&Value::String(ref s))) => Ok(s == name),
Ok(_) => Err(CEK::TypeError.into_error()),
Err(e) => Err(e).map_err_into(CEK::HeaderReadError),
}
@@ -279,7 +280,7 @@ impl<'a> Iterator for CategoryNameIter<'a> {
.map_err_into(CEK::StoreReadError)
.and_then(|fle| fle.ok_or(CEK::StoreReadError.into_error()))
.and_then(|fle| match fle.get_header().read(&query) {
- Ok(&Value::String(ref s)) => Ok(Category::from(s.clone())),
+ Ok(Some(&Value::String(ref s))) => Ok(Category::from(s.clone())),
Ok(_) => Err(CEK::TypeError.into_error()),
Err(e) => Err(e).map_err_into(CEK::HeaderReadError),
})
diff --git a/libimagentrydatetime/Cargo.toml b/libimagentrydatetime/Cargo.toml
index 1c810e9..119487f 100644
--- a/libimagentrydatetime/Cargo.toml
+++ b/libimagentrydatetime/Cargo.toml
@@ -15,7 +15,7 @@ homepage = "http://imag-pim.org"
[dependencies]
chrono = "0.3"
-toml-query = "0.2"
+toml-query = "0.3"
lazy_static = "0.2"
toml = "0.4"
diff --git a/libimagentrydatetime/src/datetime.rs b/libimagentrydatetime/src/datetime.rs
index b78dac0..6e7911b 100644
--- a/libimagentrydatetime/src/datetime.rs
+++ b/libimagentrydatetime/src/datetime.rs
@@ -65,9 +65,10 @@ impl EntryDate for Entry {
.map_err_into(DEK::ReadDateError)
.and_then(|v| {
match v {
- &Value::String(ref s) => s.parse::<NaiveDateTime>()
+ Some(&Value::String(ref s)) => s.parse::<NaiveDateTime>()
.map_err_into(DEK::DateTimeParsingError),
- _ => Err(DEK::DateHeaderFieldTypeError.into_error()),
+ Some(_) => Err(DEK::DateHeaderFieldTypeError.into_error()),
+ _ => Err(DEK::ReadDateError.into_error()),
}
})
}
@@ -131,9 +132,10 @@ impl EntryDate for Entry {
.map_err_into(DEK::ReadDateTimeRangeError)
.and_then(|v| {
match v {
- &Value::String(ref s) => s.parse::<NaiveDateTime>()
+ Some(&Value::String(ref s)) => s.parse::<NaiveDateTime>()
.map_err_into(DEK::DateTimeParsingError),
- _ => Err(DEK::DateHeaderFieldTypeError.into_error()),
+ Some(_) => Err(DEK::DateHeaderFieldTypeError.into_error()),
+ _ => Err(DEK::ReadDateError.into_error()),
}
}));
@@ -143,9 +145,10 @@ impl EntryDate for Entry {
.map_err_into(DEK::ReadDateTimeRangeError)
.and_then(|v| {
match v {
- &Value::String(ref s) => s.parse::<NaiveDateTime>()
+ Some(&Value::String(ref s)) => s.parse::<NaiveDateTime>()
.map_err_into(DEK::DateTimeParsingError),
- _ => Err(DEK::DateHeaderFieldTypeError.into_error()),
+ Some(_) => Err(DEK::DateHeaderFieldTypeError.into_error()),
+ _ => Err(DEK::ReadDateError.into_error()),
}
}));
@@ -250,6 +253,9 @@ mod tests {
assert!(hdr_field.is_ok());
let hdr_field = hdr_field.unwrap();
+ assert!(hdr_field.is_some());
+ let hdr_field = hdr_field.unwrap();
+
match *hdr_field {
Value::String(ref s) => assert_eq!("2000-01-02T03:04:05", s),
_ => assert!(false, "Wrong header type"),
@@ -315,7 +321,10 @@ mod tests {
let hdr_field = entry.get_header().read(&DATE_HEADER_LOCATION);
- assert!(hdr_field.is_err(), format!("Expected Err(_), got: {:?}", hdr_field));
+ assert!(hdr_field.is_ok());
+ let hdr_field = hdr_field.unwrap();
+
+ assert!(hdr_field.is_none());
}
}
diff --git a/libimagtimetrack/Cargo.toml b/libimagtimetrack/Cargo.toml
index f7eaad7..7be7171 100644
--- a/libimagtimetrack/Cargo.toml
+++ b/libimagtimetrack/Cargo.toml
@@ -17,7 +17,7 @@ homepage = "http://imag-pim.org"
filters = "0.1"
chrono = "0.3"
toml = "0.4"
-toml-query = "0.2"
+toml-query = "0.3"
lazy_static = "0.2"
[dependencies.libimagerror]
diff --git a/libimagtimetrack/src/event.rs b/libimagtimetrack/src/event.rs
index 40b6e34..6ee2c10 100644
--- a/libimagtimetrack/src/event.rs
+++ b/libimagtimetrack/src/event.rs
@@ -43,13 +43,13 @@ pub trait TimeTracking {
fn set_start_datetime(&mut self, dt: NaiveDateTime) -> Result<()>;
- fn get_start_datetime(&self) -> Result<NaiveDateTime>;
+ fn get_start_datetime(&self) -> Result<Option<NaiveDateTime>>;
fn delete_start_datetime(&mut self) -> Result<()>;
fn set_end_datetime(&mut self, dt: NaiveDateTime) -> Result<()>;
- fn get_end_datetime(&self) -> Result<NaiveDateTime>;
+ fn get_end_datetime(&self) -> Result<Option<NaiveDateTime>>;
fn delete_end_datetime(&mut self) -> Result<()>;
@@ -68,7 +68,7 @@ impl TimeTracking for Entry {
.map(|_| ())
}
- fn get_start_datetime(&self) -> Result<NaiveDateTime> {
+ fn get_start_datetime(&self) -> Result<Option<NaiveDateTime>> {
self.get_header()
.read(DATE_TIME_START_HEADER_PATH)
.map_err_into(TTEK::HeaderReadError)
@@ -91,7 +91,7 @@ impl TimeTracking for Entry {
.map(|_| ())
}
- fn get_end_datetime(&self) -> Result<NaiveDateTime> {
+ fn get_end_datetime(&self) -> Result<Option<NaiveDateTime>> {
self.get_header()
.read(DATE_TIME_END_HEADER_PATH)
.map_err_into(TTEK::HeaderReadError)
@@ -123,13 +123,16 @@ impl TimeTracking for Entry {
}
-fn header_value_to_dt(val: &Value) -> Result<NaiveDateTime> {
+fn header_value_to_dt(val: Option<&Value>) -> Result<Option<NaiveDateTime>> {
match val {
- &Value::String(ref s) => {
+ Some(&Value::String(ref s)) => {
NaiveDateTime::parse_from_str(s, DATE_TIME_FORMAT)
.map_err_into(TTEK::DateTimeParserError)
+ .map(Some)
+
},
- _ => Err(TTEK::HeaderFieldTypeError.into_error())
+ Some(_) => Err(TTEK::HeaderFieldTypeError.into_error()),
+ None => Ok(None),
}
}
diff --git a/libimagtodo/Cargo.toml b/libimagtodo/Cargo.toml
index 3f4c5bf..791b681 100644
--- a/libimagtodo/Cargo.toml
+++ b/libimagtodo/Cargo.toml
@@ -18,7 +18,7 @@ semver = "0.2"
task-hookrs = "0.2.2"
uuid = "0.3"
toml = "0.4.*"
-toml-query = "0.2.*"
+toml-query = "0.3.*"
is-match = "0.1.*"
log = "0.3"
serde_json = "0.8"