summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2018-05-11 14:22:35 +0200
committerMatthias Beyer <mail@beyermatthias.de>2018-05-11 15:45:50 +0200
commit3b97db5c258d0700957ad41c6884badc27cd20c2 (patch)
tree88a3cebdf12b9a65b8594b082f566a1af8292912
parent7c44bc1aa3dfc87c15ad76ce44e2c5f31b68d4b4 (diff)
downloadimag-3b97db5c258d0700957ad41c6884badc27cd20c2.zip
imag-3b97db5c258d0700957ad41c6884badc27cd20c2.tar.gz
Fix: Duplicated printing of entries with "show --all"
The problem was that the used `Diary::diary_names()` iterator does not call `unique()` on its output. That decision was made because the return type would get more complicated with that feature. Now that rustc 1.26 with Impl Trait is out, we can refactor the return types of these functions (so also with `Diary::diary_names()`) to automatically do this.
-rw-r--r--bin/domain/imag-log/src/main.rs11
1 files changed, 10 insertions, 1 deletions
diff --git a/bin/domain/imag-log/src/main.rs b/bin/domain/imag-log/src/main.rs
index befed15..053f06e 100644
--- a/bin/domain/imag-log/src/main.rs
+++ b/bin/domain/imag-log/src/main.rs
@@ -104,6 +104,8 @@ fn main() {
}
fn show(rt: &Runtime) {
+ use std::borrow::Cow;
+
use libimagdiary::iter::DiaryEntryIterator;
use libimagdiary::entry::DiaryEntry;
@@ -114,13 +116,19 @@ fn show(rt: &Runtime) {
.collect(),
None => if scmd.is_present("show-all") {
+ debug!("Showing for all diaries");
rt.store()
.diary_names()
.map_err_trace_exit_unwrap(1)
.map(|diary_name| {
let diary_name = diary_name.map_err_trace_exit_unwrap(1);
- Diary::entries(rt.store(), &diary_name).map_err_trace_exit_unwrap(1)
+ debug!("Getting entries for Diary: {}", diary_name);
+ let entries = Diary::entries(rt.store(), &diary_name).map_err_trace_exit_unwrap(1);
+ let diary_name = Cow::from(diary_name);
+ (entries, diary_name)
})
+ .unique_by(|tpl| tpl.1.clone())
+ .map(|tpl| tpl.0)
.collect()
} else {
// showing default logs
@@ -144,6 +152,7 @@ fn show(rt: &Runtime) {
.sorted_by_key(|&(ref id, _)| id.clone())
.into_iter()
.map(|(id, entry)| {
+ debug!("Found entry: {:?}", entry);
writeln!(rt.stdout(),
"{dname: >10} - {y: >4}-{m:0>2}-{d:0>2}T{H:0>2}:{M:0>2} - {text}",
dname = id.diary_name(),