2016-06-08 17:40:13 +00:00
|
|
|
use std::path::PathBuf;
|
|
|
|
use std::process::exit;
|
|
|
|
|
|
|
|
use libimagdiary::diary::Diary;
|
|
|
|
use libimagdiary::error::DiaryError as DE;
|
|
|
|
use libimagdiary::error::DiaryErrorKind as DEK;
|
|
|
|
use libimagentrylist::listers::core::CoreLister;
|
|
|
|
use libimagentrylist::lister::Lister;
|
|
|
|
use libimagrt::runtime::Runtime;
|
2016-07-04 18:13:45 +00:00
|
|
|
use libimagstore::store::Entry;
|
2016-06-08 17:40:13 +00:00
|
|
|
use libimagstore::storeid::StoreId;
|
|
|
|
use libimagerror::trace::trace_error;
|
|
|
|
|
|
|
|
use util::get_diary_name;
|
|
|
|
|
|
|
|
pub fn list(rt: &Runtime) {
|
|
|
|
let diaryname = get_diary_name(rt);
|
|
|
|
if diaryname.is_none() {
|
|
|
|
warn!("No diary selected. Use either the configuration file or the commandline option");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
let diaryname = diaryname.unwrap();
|
|
|
|
|
|
|
|
fn location_to_listing_string(id: &StoreId, base: &PathBuf) -> String {
|
|
|
|
id.strip_prefix(base)
|
|
|
|
.map_err(|e| trace_error(&e))
|
|
|
|
.ok()
|
|
|
|
.and_then(|p| p.to_str().map(String::from))
|
|
|
|
.unwrap_or(String::from("<<Path Parsing Error>>"))
|
|
|
|
}
|
|
|
|
|
|
|
|
let diary = Diary::open(rt.store(), &diaryname[..]);
|
|
|
|
debug!("Diary opened: {:?}", diary);
|
|
|
|
diary.entries()
|
|
|
|
.and_then(|es| {
|
|
|
|
debug!("Iterator for listing: {:?}", es);
|
|
|
|
|
|
|
|
let es = es.filter_map(|a| {
|
|
|
|
debug!("Filtering: {:?}", a);
|
|
|
|
a.ok()
|
|
|
|
}).map(|e| e.into());
|
|
|
|
|
|
|
|
let base = rt.store().path();
|
|
|
|
|
2016-07-04 18:13:45 +00:00
|
|
|
CoreLister::new(&move |e: &Entry| location_to_listing_string(e.get_location(), base))
|
2016-06-08 17:40:13 +00:00
|
|
|
.list(es) // TODO: Do not ignore non-ok()s
|
|
|
|
.map_err(|e| DE::new(DEK::IOError, Some(Box::new(e))))
|
|
|
|
})
|
|
|
|
.map(|_| debug!("Ok"))
|
|
|
|
.map_err(|e| trace_error(&e))
|
|
|
|
.ok();
|
|
|
|
}
|
|
|
|
|