summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2018-04-22 14:33:53 +0200
committerMatthias Beyer <mail@beyermatthias.de>2018-04-22 14:33:53 +0200
commitee75d2309c01e4c49718a2355de4c3b05c298745 (patch)
treec1f1aa76f3fabff18a69bf376139ea21fcdd668c /bin
parent495ad62be63b527588ac9a87066f25dda06e8235 (diff)
Fix: imag-log show should order by datetime
Diffstat (limited to 'bin')
-rw-r--r--bin/domain/imag-log/Cargo.toml1
-rw-r--r--bin/domain/imag-log/src/main.rs58
2 files changed, 32 insertions, 27 deletions
diff --git a/bin/domain/imag-log/Cargo.toml b/bin/domain/imag-log/Cargo.toml
index 86390e65..4349d063 100644
--- a/bin/domain/imag-log/Cargo.toml
+++ b/bin/domain/imag-log/Cargo.toml
@@ -26,6 +26,7 @@ log = "0.3"
toml = "0.4"
toml-query = "0.6"
is-match = "0.1"
+itertools = "0.7"
libimagstore = { version = "0.8.0", path = "../../../lib/core/libimagstore" }
libimagrt = { version = "0.8.0", path = "../../../lib/core/libimagrt" }
diff --git a/bin/domain/imag-log/src/main.rs b/bin/domain/imag-log/src/main.rs
index 277ccaea..befed156 100644
--- a/bin/domain/imag-log/src/main.rs
+++ b/bin/domain/imag-log/src/main.rs
@@ -37,6 +37,7 @@ extern crate clap;
#[macro_use] extern crate log;
extern crate toml;
extern crate toml_query;
+extern crate itertools;
extern crate libimaglog;
#[macro_use] extern crate libimagrt;
@@ -51,6 +52,7 @@ use libimagrt::setup::generate_runtime_setup;
use libimagerror::trace::MapErrTrace;
use libimagerror::io::ToExitCode;
use libimagerror::exit::ExitUnwrap;
+use libimagerror::iter::TraceIterator;
use libimagdiary::diary::Diary;
use libimaglog::log::Log;
use libimaglog::error::LogError as LE;
@@ -60,6 +62,7 @@ mod ui;
use ui::build_ui;
use toml::Value;
+use itertools::Itertools;
fn main() {
let version = make_imag_version!();
@@ -126,33 +129,34 @@ fn show(rt: &Runtime) {
};
for iter in iters {
- let _ = iter.into_get_iter(rt.store()).map(|element| {
- let e = element.map_err_trace_exit_unwrap(1);
-
- if e.is_none() {
- warn!("Failed to retrieve an entry from an existing store id");
- return Ok(())
- }
- let e = e.unwrap(); // safe with above check
-
- if !e.is_log().map_err_trace_exit_unwrap(1) {
- return Ok(());
- }
-
- let id = e.diary_id().map_err_trace_exit_unwrap(1);
- 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(),
- y = id.year(),
- m = id.month(),
- d = id.day(),
- H = id.hour(),
- M = id.minute(),
- text = e.get_content())
- .to_exit_code()
- })
- .collect::<Result<Vec<()>, _>>()
- .unwrap_or_exit();
+ let _ = iter
+ .into_get_iter(rt.store())
+ .trace_unwrap_exit(1)
+ .filter_map(|opt| {
+ if opt.is_none() {
+ warn!("Failed to retrieve an entry from an existing store id");
+ }
+
+ opt
+ })
+ .filter(|e| e.is_log().map_err_trace_exit_unwrap(1))
+ .map(|entry| (entry.diary_id().map_err_trace_exit_unwrap(1), entry))
+ .sorted_by_key(|&(ref id, _)| id.clone())
+ .into_iter()
+ .map(|(id, 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(),
+ y = id.year(),
+ m = id.month(),
+ d = id.day(),
+ H = id.hour(),
+ M = id.minute(),
+ text = entry.get_content())
+ .to_exit_code()
+ })
+ .collect::<Result<Vec<()>, _>>()
+ .unwrap_or_exit();
}
}