Add Task::import()
This commit is contained in:
parent
e63f17d51e
commit
0041a648c3
1 changed files with 14 additions and 1 deletions
|
@ -1,16 +1,18 @@
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
use std::ops::{Deref, DerefMut};
|
use std::ops::{Deref, DerefMut};
|
||||||
|
use std::io::BufRead;
|
||||||
|
|
||||||
use toml::Value;
|
use toml::Value;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
use task_hookrs::task::Task as TTask;
|
use task_hookrs::task::Task as TTask;
|
||||||
|
use task_hookrs::import::{import_task, import_tasks};
|
||||||
|
|
||||||
use libimagstore::store::{FileLockEntry, Store};
|
use libimagstore::store::{FileLockEntry, Store};
|
||||||
use libimagstore::storeid::{IntoStoreId, StoreIdIterator, StoreId};
|
use libimagstore::storeid::{IntoStoreId, StoreIdIterator, StoreId};
|
||||||
use module_path::ModuleEntryPath;
|
use module_path::ModuleEntryPath;
|
||||||
|
|
||||||
use error::{TodoError, TodoErrorKind};
|
use error::{TodoError, TodoErrorKind, MapErrInto};
|
||||||
use result::Result;
|
use result::Result;
|
||||||
|
|
||||||
/// Task struct containing a `FileLockEntry`
|
/// Task struct containing a `FileLockEntry`
|
||||||
|
@ -24,6 +26,17 @@ impl<'a> Task<'a> {
|
||||||
Task(fle)
|
Task(fle)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn import<R: BufRead>(store: &'a Store, mut r: R) -> Result<(Task<'a>, Uuid)> {
|
||||||
|
let mut line = String::new();
|
||||||
|
r.read_line(&mut line);
|
||||||
|
import_task(&line.as_str())
|
||||||
|
.map_err_into(TodoErrorKind::ImportError)
|
||||||
|
.and_then(|t| {
|
||||||
|
let uuid = t.uuid().clone();
|
||||||
|
t.into_task(store).map(|t| (t, uuid))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
pub fn delete_by_uuid(store: &Store, uuid: Uuid) -> Result<()> {
|
pub fn delete_by_uuid(store: &Store, uuid: Uuid) -> Result<()> {
|
||||||
store.delete(ModuleEntryPath::new(format!("taskwarrior/{}", uuid)).into_storeid())
|
store.delete(ModuleEntryPath::new(format!("taskwarrior/{}", uuid)).into_storeid())
|
||||||
.map_err(|e| TodoError::new(TodoErrorKind::StoreError, Some(Box::new(e))))
|
.map_err(|e| TodoError::new(TodoErrorKind::StoreError, Some(Box::new(e))))
|
||||||
|
|
Loading…
Reference in a new issue