summaryrefslogtreecommitdiffstats
path: root/bin/domain/imag-todo/src/lib.rs
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2019-11-10 22:24:58 +0100
committerMatthias Beyer <mail@beyermatthias.de>2019-12-01 13:00:00 +0100
commitbd4a839cb96304f4fd049abb3fc4727111a494ae (patch)
tree226ad40e76bfdb39401355ed6afa6eec29d49d28 /bin/domain/imag-todo/src/lib.rs
parentc2d4ec5fefe5de8871d974e7dd61af0fa618ae91 (diff)
downloadimag-bd4a839cb96304f4fd049abb3fc4727111a494ae.tar.gz
imag-bd4a839cb96304f4fd049abb3fc4727111a494ae.tar.xz
Diffstat (limited to 'bin/domain/imag-todo/src/lib.rs')
-rw-r--r--bin/domain/imag-todo/src/lib.rs80
1 files changed, 49 insertions, 31 deletions
diff --git a/bin/domain/imag-todo/src/lib.rs b/bin/domain/imag-todo/src/lib.rs
index 1ee53439..d3c3fe51 100644
--- a/bin/domain/imag-todo/src/lib.rs
+++ b/bin/domain/imag-todo/src/lib.rs
@@ -251,15 +251,6 @@ fn list_todos(rt: &Runtime, matcher: &StatusMatcher, show_hidden: bool) -> Resul
use filters::failable::filter::FailableFilter;
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 {
details: bool,
}
@@ -306,30 +297,57 @@ fn list_todos(rt: &Runtime, matcher: &StatusMatcher, show_hidden: bool) -> Resul
}
}
- let viewer = TodoViewer { details: false };
-
- rt.store()
- .get_todos()?
- .into_get_iter()
- .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))) {
- Err(e) => Some(Err(e)),
- Ok((st, e)) => if matcher.matches(st) {
- Some(Ok(e))
- } else {
- None
+ 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 };
+
+ 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))
+ };
+
+ iter
+ .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)
- })
- .collect()
+ rt.report_touched(entry.get_location()).map_err(Error::from)
+ })
+ .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