From f6971c689605ed577561da0d94bd3daf842ee74c Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Wed, 8 Jun 2016 19:35:59 +0200 Subject: [PATCH] Implement view() --- imag-diary/Cargo.toml | 3 +++ imag-diary/src/main.rs | 30 ++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/imag-diary/Cargo.toml b/imag-diary/Cargo.toml index 725c1364..2edf2daa 100644 --- a/imag-diary/Cargo.toml +++ b/imag-diary/Cargo.toml @@ -18,6 +18,9 @@ path = "../libimagdiary" [dependencies.libimagentrylist] path = "../libimagentrylist" +[dependencies.libimagentryview] +path = "../libimagentryview" + [dependencies.libimagerror] path = "../libimagerror" diff --git a/imag-diary/src/main.rs b/imag-diary/src/main.rs index b696f552..6b009a39 100644 --- a/imag-diary/src/main.rs +++ b/imag-diary/src/main.rs @@ -5,6 +5,7 @@ extern crate chrono; extern crate libimagdiary; extern crate libimagentrylist; +extern crate libimagentryview; extern crate libimaginteraction; extern crate libimagrt; extern crate libimagstore; @@ -22,12 +23,15 @@ use libimagdiary::error::DiaryError as DE; use libimagdiary::error::DiaryErrorKind as DEK; use libimagentrylist::listers::core::CoreLister; use libimagentrylist::lister::Lister; +use libimagentryview::viewer::Viewer; +use libimagentryview::builtin::plain::PlainViewer; use libimagrt::edit::Edit; use libimagrt::runtime::Runtime; use libimagstore::storeid::StoreId; use libimagerror::trace::trace_error; use libimagtimeui::datetime::DateTime; use libimagtimeui::parse::Parse; +use libimagstore::store::FileLockEntry; mod ui; @@ -59,6 +63,7 @@ fn main() { "edit" => edit(&rt), "list" => list(&rt), "diary" => diary(&rt), + "view" => view(&rt), _ => { debug!("Unknown command"); // More error handling }, @@ -293,6 +298,31 @@ fn diary(rt: &Runtime) { unimplemented!() } +fn view(rt: &Runtime) { + let diaryname = get_diary_name(rt); + if diaryname.is_none() { + warn!("No diary name"); + exit(1); + } + let diaryname = diaryname.unwrap(); + let diary = Diary::open(rt.store(), &diaryname[..]); + let show_header = rt.cli().subcommand_matches("view").unwrap().is_present("show-header"); + + match diary.entries() { + Ok(entries) => { + let pv = PlainViewer::new(show_header); + for entry in entries.into_iter().filter_map(Result::ok) { + let id = entry.diary_id(); + println!("{} :\n", id); + pv.view_entry(&entry); + println!("\n---\n"); + } + }, + Err(e) => { + trace_error(&e); + }, + } +} fn get_diary_name(rt: &Runtime) -> Option { use libimagdiary::config::get_default_diary_name;