imag/imag-diary/src/view.rs

37 lines
1 KiB
Rust
Raw Normal View History

2016-06-08 17:40:13 +00:00
use std::process::exit;
use libimagdiary::diary::Diary;
use libimagentryview::viewer::Viewer;
use libimagentryview::builtin::plain::PlainViewer;
use libimagrt::runtime::Runtime;
use libimagerror::trace::trace_error;
use util::get_diary_name;
pub 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);
if let Err(e) = pv.view_entry(&entry) {
trace_error(&e);
};
2016-06-08 17:40:13 +00:00
println!("\n---\n");
}
},
Err(e) => trace_error(&e),
2016-06-08 17:40:13 +00:00
}
}