Merge branch 'imag-todo/ids-from-stdin' into master
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
This commit is contained in:
commit
49eb0c13e9
1 changed files with 48 additions and 30 deletions
|
@ -253,15 +253,6 @@ fn list_todos(rt: &Runtime, matcher: &StatusMatcher, show_hidden: bool) -> Resul
|
||||||
use filters::failable::filter::FailableFilter;
|
use filters::failable::filter::FailableFilter;
|
||||||
debug!("Listing todos with status filter {:?}", matcher);
|
debug!("Listing todos with status filter {:?}", matcher);
|
||||||
|
|
||||||
let now = {
|
|
||||||
let now = chrono::offset::Local::now();
|
|
||||||
NaiveDateTime::new(now.date().naive_local(), now.time())
|
|
||||||
};
|
|
||||||
|
|
||||||
let filter_hidden = |todo: &FileLockEntry<'_>| -> Result<bool> {
|
|
||||||
Ok(todo.get_hidden()?.map(|hid| hid > now).unwrap_or(true))
|
|
||||||
};
|
|
||||||
|
|
||||||
struct TodoViewer {
|
struct TodoViewer {
|
||||||
details: bool,
|
details: bool,
|
||||||
}
|
}
|
||||||
|
@ -308,30 +299,57 @@ fn list_todos(rt: &Runtime, matcher: &StatusMatcher, show_hidden: bool) -> Resul
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let viewer = TodoViewer { details: false };
|
fn process<'a, I>(rt: &Runtime, matcher: &StatusMatcher, show_hidden: bool, iter: I) -> Result<()>
|
||||||
|
where I: Iterator<Item = Result<FileLockEntry<'a>>> + Sized
|
||||||
|
{
|
||||||
|
let viewer = TodoViewer { details: false };
|
||||||
|
|
||||||
rt.store()
|
let now = {
|
||||||
.get_todos()?
|
let now = chrono::offset::Local::now();
|
||||||
.into_get_iter()
|
NaiveDateTime::new(now.date().naive_local(), now.time())
|
||||||
.map_inner_ok_or_else(|| err_msg("Did not find one entry"))
|
};
|
||||||
.filter_map(|r| {
|
|
||||||
match r.and_then(|e| e.get_status().map(|s| (s, e))) {
|
let filter_hidden = |todo: &FileLockEntry<'_>| -> Result<bool> {
|
||||||
Err(e) => Some(Err(e)),
|
Ok(todo.get_hidden()?.map(|hid| hid > now).unwrap_or(true))
|
||||||
Ok((st, e)) => if matcher.matches(st) {
|
};
|
||||||
Some(Ok(e))
|
|
||||||
} else {
|
iter
|
||||||
None
|
.filter_map(|r| {
|
||||||
|
match r.and_then(|e| e.get_status().map(|s| (s, e))) {
|
||||||
|
Err(e) => Some(Err(e)),
|
||||||
|
Ok((st, e)) => if matcher.matches(st) {
|
||||||
|
Some(Ok(e))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.and_then_ok(|entry| {
|
||||||
|
if !rt.output_is_pipe() && (show_hidden || filter_hidden.filter(&entry)?) {
|
||||||
|
viewer.view_entry(&entry, &mut rt.stdout())?;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
})
|
|
||||||
.and_then_ok(|entry| {
|
|
||||||
if !rt.output_is_pipe() && (show_hidden || filter_hidden.filter(&entry)?) {
|
|
||||||
viewer.view_entry(&entry, &mut rt.stdout())?;
|
|
||||||
}
|
|
||||||
|
|
||||||
rt.report_touched(entry.get_location()).map_err(Error::from)
|
rt.report_touched(entry.get_location()).map_err(Error::from)
|
||||||
})
|
})
|
||||||
.collect()
|
.collect()
|
||||||
|
};
|
||||||
|
|
||||||
|
if rt.ids_from_stdin() {
|
||||||
|
let iter = rt.ids::<crate::ui::PathProvider>()?
|
||||||
|
.ok_or_else(|| err_msg("No ids supplied"))?
|
||||||
|
.into_iter()
|
||||||
|
.map(Ok)
|
||||||
|
.into_get_iter(rt.store())
|
||||||
|
.map_inner_ok_or_else(|| err_msg("Did not find one entry"));
|
||||||
|
|
||||||
|
process(&rt, matcher, show_hidden, iter)
|
||||||
|
} else {
|
||||||
|
let iter = rt.store().get_todos()?
|
||||||
|
.into_get_iter()
|
||||||
|
.map_inner_ok_or_else(|| err_msg("Did not find one entry"));
|
||||||
|
|
||||||
|
process(&rt, matcher, show_hidden, iter)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Generic todo items list function
|
/// Generic todo items list function
|
||||||
|
|
Loading…
Reference in a new issue