imag/imag-diary/src/list.rs

64 lines
2.2 KiB
Rust
Raw Normal View History

//
// imag - the personal information management suite for the commandline
// Copyright (C) 2015, 2016 Matthias Beyer <mail@beyermatthias.de> and contributors
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; version
// 2.1 of the License.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
2016-06-08 17:40:13 +00:00
use libimagdiary::diary::Diary;
use libimagdiary::error::DiaryErrorKind as DEK;
2016-09-04 15:56:38 +00:00
use libimagdiary::error::MapErrInto;
2016-06-08 17:40:13 +00:00
use libimagentrylist::listers::core::CoreLister;
use libimagentrylist::lister::Lister;
use libimagrt::runtime::Runtime;
use libimagstore::store::Entry;
2016-09-05 17:30:21 +00:00
use libimagutil::warn_exit::warn_exit;
use libimagerror::trace::MapErrTrace;
use libimagutil::debug_result::*;
2016-06-08 17:40:13 +00:00
use util::get_diary_name;
pub fn list(rt: &Runtime) {
2016-09-05 17:30:21 +00:00
let diaryname = get_diary_name(rt)
.unwrap_or_else(|| warn_exit("No diary selected. Use either the configuration file or the commandline option", 1));
2016-06-08 17:40:13 +00:00
fn entry_to_location_listing_string(e: &Entry) -> String {
e.get_location().clone()
.without_base()
.to_str()
.map_err_trace()
2016-06-08 17:40:13 +00:00
.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| a.map_dbg(|e| format!("Filtering: {:?}", e)).ok())
.map(|e| e.into());
2016-06-08 17:40:13 +00:00
CoreLister::new(&entry_to_location_listing_string)
2016-06-08 17:40:13 +00:00
.list(es) // TODO: Do not ignore non-ok()s
2016-09-04 15:56:38 +00:00
.map_err_into(DEK::IOError)
2016-06-08 17:40:13 +00:00
})
.map_dbg_str("Ok")
.map_err_trace()
2016-06-08 17:40:13 +00:00
.ok();
}