Rewrite imag-diary for new Diary::entries() interface

This commit is contained in:
Matthias Beyer 2018-03-02 21:28:40 +01:00
parent 8c37fb865a
commit affd15a890
2 changed files with 14 additions and 14 deletions

View file

@ -38,16 +38,8 @@ pub fn list(rt: &Runtime) {
Diary::entries(rt.store(), &diaryname)
.map_dbg_str("Ok")
.map_err_trace_exit_unwrap(1)
.filter_map(|entry| {
entry
.map_dbg(|e| format!("Filtering: {:?}", e))
.map_err_trace() // error tracing here
.ok() // so we can ignore errors here
})
.for_each(|e| {
writeln!(out, "{}", e
.get_location()
.clone()
.for_each(|id| {
writeln!(out, "{}", id
.without_base()
.to_str()
.map_err_trace()

View file

@ -22,6 +22,7 @@ use libimagdiary::viewer::DiaryViewer as DV;
use libimagrt::runtime::Runtime;
use libimagerror::trace::MapErrTrace;
use libimagutil::warn_exit::warn_exit;
use libimagstore::iter::get::StoreIdGetIteratorExtension;
use util::get_diary_name;
@ -29,9 +30,16 @@ pub fn view(rt: &Runtime) {
let diaryname = get_diary_name(rt).unwrap_or_else(|| warn_exit("No diary name", 1));
let hdr = rt.cli().subcommand_matches("view").unwrap().is_present("show-header");
Diary::entries(rt.store(), &diaryname)
.and_then(|entries| DV::new(hdr).view_entries(entries.into_iter().filter_map(Result::ok)))
.map_err_trace()
.ok();
let entries = Diary::entries(rt.store(), &diaryname)
.map_err_trace_exit_unwrap(1)
.into_get_iter(rt.store())
.filter_map(Result::ok)
.map(|e| e.unwrap_or_else(|| {
error!("Failed to fetch entry");
::std::process::exit(1)
}));
DV::new(hdr).view_entries(entries)
.map_err_trace_exit_unwrap(1);
}