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);
|
2016-07-31 08:39:43 +00:00
|
|
|
if let Err(e) = pv.view_entry(&entry) {
|
|
|
|
trace_error(&e);
|
|
|
|
};
|
2016-06-08 17:40:13 +00:00
|
|
|
println!("\n---\n");
|
|
|
|
}
|
|
|
|
},
|
2016-07-15 19:56:53 +00:00
|
|
|
Err(e) => trace_error(&e),
|
2016-06-08 17:40:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|