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