Reformat
This commit is contained in:
parent
813d2d6367
commit
e57568feb8
|
@ -154,7 +154,10 @@ impl GeneratedTask for Task {
|
|||
|
||||
fn check_ignores(cache: &TaskCache) -> Result<()> {
|
||||
if *cache.ignore() != vec![TS::Deleted] {
|
||||
return Err("Don't use generate with a TaskCache with ignores other than 'TaskStatus::Deleted'".into());
|
||||
return Err(
|
||||
"Don't use generate with a TaskCache with ignores other than 'TaskStatus::Deleted'"
|
||||
.into(),
|
||||
);
|
||||
};
|
||||
Ok(())
|
||||
}
|
||||
|
@ -176,69 +179,69 @@ fn w<'a>(c: &'a mut TaskCache, u: &Uuid) -> Result<&'a mut Task> {
|
|||
fn process_matches(cache: &mut TaskCache, matches: Vec<(Uuid, Task)>) -> Result<()> {
|
||||
let c = cache;
|
||||
for (u, new) in matches {
|
||||
if r(c,&u)?.status() != new.status() {
|
||||
*w(c,&u)?.status_mut() = new.status().clone();
|
||||
if r(c, &u)?.status() != new.status() {
|
||||
*w(c, &u)?.status_mut() = new.status().clone();
|
||||
}
|
||||
if r(c,&u)?.description() != new.description() {
|
||||
*w(c,&u)?.description_mut() = new.description().clone();
|
||||
if r(c, &u)?.description() != new.description() {
|
||||
*w(c, &u)?.description_mut() = new.description().clone();
|
||||
}
|
||||
if let Some(ann) = new.annotations() {
|
||||
if r(c,&u)?.annotations().map(|x| x != ann) == Some(true) {
|
||||
w(c,&u)?.annotations_mut().map(|o| *o = ann.clone());
|
||||
if r(c, &u)?.annotations().map(|x| x != ann) == Some(true) {
|
||||
w(c, &u)?.annotations_mut().map(|o| *o = ann.clone());
|
||||
}
|
||||
}
|
||||
if let Some(dep) = new.depends() {
|
||||
if r(c,&u)?.depends().map(|x| x != dep) == Some(true) {
|
||||
w(c,&u)?.depends_mut().map(|o| *o = dep.clone());
|
||||
if r(c, &u)?.depends().map(|x| x != dep) == Some(true) {
|
||||
w(c, &u)?.depends_mut().map(|o| *o = dep.clone());
|
||||
}
|
||||
}
|
||||
if let Some(due) = new.due() {
|
||||
if r(c,&u)?.due().map(|x| x != due) == Some(true) {
|
||||
w(c,&u)?.due_mut().map(|o| *o = due.clone());
|
||||
if r(c, &u)?.due().map(|x| x != due) == Some(true) {
|
||||
w(c, &u)?.due_mut().map(|o| *o = due.clone());
|
||||
}
|
||||
}
|
||||
if let Some(end) = new.end() {
|
||||
if r(c,&u)?.end().map(|x| x != end) == Some(true) {
|
||||
w(c,&u)?.end_mut().map(|o| *o = end.clone());
|
||||
if r(c, &u)?.end().map(|x| x != end) == Some(true) {
|
||||
w(c, &u)?.end_mut().map(|o| *o = end.clone());
|
||||
}
|
||||
}
|
||||
if let Some(ann) = new.annotations() {
|
||||
if r(c,&u)?.annotations().map(|x| x != ann) == Some(true) {
|
||||
w(c,&u)?.annotations_mut().map(|o| *o = ann.clone());
|
||||
if r(c, &u)?.annotations().map(|x| x != ann) == Some(true) {
|
||||
w(c, &u)?.annotations_mut().map(|o| *o = ann.clone());
|
||||
}
|
||||
}
|
||||
if let Some(recur) = new.recur() {
|
||||
if r(c,&u)?.recur().map(|x| x != recur) == Some(true) {
|
||||
w(c,&u)?.recur_mut().map(|o| *o = recur.clone());
|
||||
if r(c, &u)?.recur().map(|x| x != recur) == Some(true) {
|
||||
w(c, &u)?.recur_mut().map(|o| *o = recur.clone());
|
||||
}
|
||||
}
|
||||
if let Some(scheduled) = new.scheduled() {
|
||||
if r(c,&u)?.scheduled().map(|x| x != scheduled) == Some(true) {
|
||||
w(c,&u)?.scheduled_mut().map(|o| *o = scheduled.clone());
|
||||
if r(c, &u)?.scheduled().map(|x| x != scheduled) == Some(true) {
|
||||
w(c, &u)?.scheduled_mut().map(|o| *o = scheduled.clone());
|
||||
}
|
||||
}
|
||||
if let Some(start) = new.start() {
|
||||
if r(c,&u)?.start().map(|x| x != start) == Some(true) {
|
||||
w(c,&u)?.start_mut().map(|o| *o = start.clone());
|
||||
if r(c, &u)?.start().map(|x| x != start) == Some(true) {
|
||||
w(c, &u)?.start_mut().map(|o| *o = start.clone());
|
||||
}
|
||||
}
|
||||
if let Some(tags) = new.tags() {
|
||||
if r(c,&u)?.tags().map(|x| x != tags) == Some(true) {
|
||||
w(c,&u)?.tags_mut().map(|o| *o = tags.clone());
|
||||
if r(c, &u)?.tags().map(|x| x != tags) == Some(true) {
|
||||
w(c, &u)?.tags_mut().map(|o| *o = tags.clone());
|
||||
}
|
||||
}
|
||||
if let Some(until) = new.until() {
|
||||
if r(c,&u)?.until().map(|x| x != until) == Some(true) {
|
||||
w(c,&u)?.until_mut().map(|o| *o = until.clone());
|
||||
if r(c, &u)?.until().map(|x| x != until) == Some(true) {
|
||||
w(c, &u)?.until_mut().map(|o| *o = until.clone());
|
||||
}
|
||||
}
|
||||
if let Some(wait) = new.wait() {
|
||||
if r(c,&u)?.wait().map(|x| x != wait) == Some(true) {
|
||||
w(c,&u)?.wait_mut().map(|o| *o = wait.clone());
|
||||
if r(c, &u)?.wait().map(|x| x != wait) == Some(true) {
|
||||
w(c, &u)?.wait_mut().map(|o| *o = wait.clone());
|
||||
}
|
||||
}
|
||||
if !(r(c,&u)?.uda() >= new.uda()) {
|
||||
w(c,&u)?.uda_mut().append(&mut new.uda().clone());
|
||||
if !(r(c, &u)?.uda() >= new.uda()) {
|
||||
w(c, &u)?.uda_mut().append(&mut new.uda().clone());
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
@ -249,15 +252,36 @@ fn process_orphans(
|
|||
orphans: HashMap<String, HashMap<String, Uuid>>,
|
||||
) -> Result<()> {
|
||||
for uuid in orphans.values().flat_map(HashMap::values) {
|
||||
match cache.get(uuid).chain_err(|| "Cache miss for orphan")?.gen_orphan() {
|
||||
O::CompleteOrphan => if *cache.get(uuid).chain_err(|| "Cache miss for orphan")?.status() != TS::Completed {
|
||||
*cache.get_mut(uuid).chain_err(|| "Cache miss for orphan")?.status_mut() = TS::Completed;
|
||||
match cache
|
||||
.get(uuid)
|
||||
.chain_err(|| "Cache miss for orphan")?
|
||||
.gen_orphan() {
|
||||
O::CompleteOrphan => {
|
||||
if *cache
|
||||
.get(uuid)
|
||||
.chain_err(|| "Cache miss for orphan")?
|
||||
.status() != TS::Completed
|
||||
{
|
||||
*cache
|
||||
.get_mut(uuid)
|
||||
.chain_err(|| "Cache miss for orphan")?
|
||||
.status_mut() = TS::Completed;
|
||||
}
|
||||
}
|
||||
O::DeleteOrphan => if *cache.get(uuid).chain_err(|| "Cache miss for orphan")?.status() != TS::Deleted {
|
||||
*cache.get_mut(uuid).chain_err(|| "Cache miss for orphan")?.status_mut() = TS::Deleted;
|
||||
}
|
||||
_ => ()
|
||||
O::DeleteOrphan => {
|
||||
if *cache
|
||||
.get(uuid)
|
||||
.chain_err(|| "Cache miss for orphan")?
|
||||
.status() != TS::Deleted
|
||||
{
|
||||
*cache
|
||||
.get_mut(uuid)
|
||||
.chain_err(|| "Cache miss for orphan")?
|
||||
.status_mut() = TS::Deleted;
|
||||
}
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
@ -269,9 +293,9 @@ pub trait TaskGenerator {
|
|||
fn get_by_gen(&self, generator: &Task) -> Option<&Task>;
|
||||
fn get_by_gen_mut(&mut self, generator: &Task) -> Option<&mut Task>;
|
||||
fn generate<T>(&mut self, generators: T) -> Result<()>
|
||||
where
|
||||
T: IntoIterator,
|
||||
T::Item: Into<Task>;
|
||||
where
|
||||
T: IntoIterator,
|
||||
T::Item: Into<Task>;
|
||||
}
|
||||
|
||||
pub fn gen_match(a: &Task, b: &Task) -> bool {
|
||||
|
@ -285,38 +309,37 @@ impl TaskGenerator for TaskCache {
|
|||
self.filter_mut(|t| gen_match(t, generator)).next()
|
||||
}
|
||||
|
||||
fn generate<T>(&mut self, generators: T) -> Result<()>
|
||||
where
|
||||
T: IntoIterator,
|
||||
T::Item: Into<Task>,
|
||||
{
|
||||
check_ignores(self)?;
|
||||
let mut orphans = HashMap::<String, HashMap<String, Uuid>>::default();
|
||||
let mut create = Vec::<Task>::default();
|
||||
let mut changes = Vec::<(Uuid, Task)>::default();
|
||||
for g in generators {
|
||||
let new = g.into();
|
||||
if let Some(old) = {
|
||||
let name = new.gen_name().chain_err(|| "gen_name missing")?;
|
||||
let id = new.gen_id().chain_err(|| "gen_id missing")?;
|
||||
fn generate<T>(&mut self, generators: T) -> Result<()>
|
||||
where
|
||||
T: IntoIterator,
|
||||
T::Item: Into<Task>,
|
||||
{
|
||||
check_ignores(self)?;
|
||||
let mut orphans = HashMap::<String, HashMap<String, Uuid>>::default();
|
||||
let mut create = Vec::<Task>::default();
|
||||
let mut changes = Vec::<(Uuid, Task)>::default();
|
||||
for g in generators {
|
||||
let new = g.into();
|
||||
if let Some(old) = {
|
||||
let name = new.gen_name().chain_err(|| "gen_name missing")?;
|
||||
let id = new.gen_id().chain_err(|| "gen_id missing")?;
|
||||
orphans
|
||||
.entry(name.clone())
|
||||
.or_insert_with(|| {
|
||||
self
|
||||
.filter(|t| t.gen_name() == Some(name))
|
||||
self.filter(|t| t.gen_name() == Some(name))
|
||||
.filter_map(|t| t.gen_id().map(|id| (id.clone(), t.uuid().clone())))
|
||||
.collect()
|
||||
})
|
||||
.remove(id)
|
||||
}
|
||||
{
|
||||
changes.push((old, new));
|
||||
} else {
|
||||
create.push(new);
|
||||
}
|
||||
}
|
||||
{
|
||||
changes.push((old, new));
|
||||
} else {
|
||||
create.push(new);
|
||||
}
|
||||
process_new(self, create);
|
||||
process_matches(self, changes)?;
|
||||
process_orphans(self, orphans)
|
||||
}
|
||||
process_new(self, create);
|
||||
process_matches(self, changes)?;
|
||||
process_orphans(self, orphans)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,17 +1,11 @@
|
|||
use dialog::{
|
||||
DialogProvider,
|
||||
errors::{
|
||||
Error,
|
||||
ErrorKind as EK},
|
||||
rofi::RofiDialogProvider
|
||||
};
|
||||
use dialog::DialogProvider;
|
||||
use dialog::errors::{Error, ErrorKind as EK};
|
||||
use dialog::rofi::RofiDialogProvider;
|
||||
|
||||
use std::{
|
||||
process::Command as StdCommand,
|
||||
os::unix::process::CommandExt,
|
||||
env::var,
|
||||
rc::Rc
|
||||
};
|
||||
use std::process::Command as StdCommand;
|
||||
use std::os::unix::process::CommandExt;
|
||||
use std::env::var;
|
||||
use std::rc::Rc;
|
||||
|
||||
use error::{Result, ResultExt};
|
||||
|
||||
|
|
Loading…
Reference in a new issue