Fix libimagtodo for new toml-query interface
This commit is contained in:
parent
5817109279
commit
eacc6777b8
3 changed files with 28 additions and 6 deletions
|
@ -18,6 +18,8 @@ semver = "0.2"
|
||||||
task-hookrs = "0.2.2"
|
task-hookrs = "0.2.2"
|
||||||
uuid = "0.3"
|
uuid = "0.3"
|
||||||
toml = "0.4.*"
|
toml = "0.4.*"
|
||||||
|
toml-query = "0.1.*"
|
||||||
|
is-match = "0.1.*"
|
||||||
log = "0.3"
|
log = "0.3"
|
||||||
serde_json = "0.8"
|
serde_json = "0.8"
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,8 @@
|
||||||
extern crate semver;
|
extern crate semver;
|
||||||
extern crate uuid;
|
extern crate uuid;
|
||||||
extern crate toml;
|
extern crate toml;
|
||||||
|
extern crate toml_query;
|
||||||
|
#[macro_use] extern crate is_match;
|
||||||
#[macro_use] extern crate log;
|
#[macro_use] extern crate log;
|
||||||
extern crate serde_json;
|
extern crate serde_json;
|
||||||
|
|
||||||
|
|
|
@ -224,6 +224,17 @@ pub trait IntoTask<'a> {
|
||||||
impl<'a> IntoTask<'a> for TTask {
|
impl<'a> IntoTask<'a> for TTask {
|
||||||
|
|
||||||
fn into_task(self, store : &'a Store) -> Result<Task<'a>> {
|
fn into_task(self, store : &'a Store) -> Result<Task<'a>> {
|
||||||
|
use toml_query::read::TomlValueReadExt;
|
||||||
|
use toml_query::set::TomlValueSetExt;
|
||||||
|
use libimagerror::into::IntoError;
|
||||||
|
|
||||||
|
// Helper for toml_query::read::TomlValueReadExt::read() return value, which does only
|
||||||
|
// return Result<T> instead of Result<Option<T>>, which is a real inconvenience.
|
||||||
|
//
|
||||||
|
let no_identifier = |e: &::toml_query::error::Error| -> bool {
|
||||||
|
is_match!(e.kind(), &::toml_query::error::ErrorKind::IdentifierNotFoundInDocument(_))
|
||||||
|
};
|
||||||
|
|
||||||
let uuid = self.uuid();
|
let uuid = self.uuid();
|
||||||
ModuleEntryPath::new(format!("taskwarrior/{}", uuid))
|
ModuleEntryPath::new(format!("taskwarrior/{}", uuid))
|
||||||
.into_storeid()
|
.into_storeid()
|
||||||
|
@ -234,14 +245,21 @@ impl<'a> IntoTask<'a> for TTask {
|
||||||
.and_then(|mut fle| {
|
.and_then(|mut fle| {
|
||||||
{
|
{
|
||||||
let mut hdr = fle.get_header_mut();
|
let mut hdr = fle.get_header_mut();
|
||||||
let read = hdr.read("todo").map_err_into(TodoErrorKind::StoreError);
|
let todo_query = String::from("todo");
|
||||||
if try!(read).is_none() {
|
|
||||||
|
if let Err(e) = hdr.read(&todo_query) {
|
||||||
|
if no_identifier(&e) {
|
||||||
try!(hdr
|
try!(hdr
|
||||||
.set("todo", Value::Table(BTreeMap::new()))
|
.set(&String::from("todo"), Value::Table(BTreeMap::new()))
|
||||||
.map_err_into(TodoErrorKind::StoreError));
|
.map_err_into(TodoErrorKind::StoreError));
|
||||||
|
} else {
|
||||||
|
let e = Box::new(e);
|
||||||
|
return Err(TodoErrorKind::StoreError.into_error_with_cause(e))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try!(hdr.set("todo.uuid", Value::String(format!("{}",uuid)))
|
try!(hdr.set(&String::from("todo.uuid"),
|
||||||
|
Value::String(format!("{}", uuid)))
|
||||||
.map_err_into(TodoErrorKind::StoreError));
|
.map_err_into(TodoErrorKind::StoreError));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue