Remove usage of libimagentrylist

This commit is contained in:
Matthias Beyer 2018-02-20 13:16:31 +01:00
parent 912a48cbfe
commit 027c4b3287
9 changed files with 90 additions and 70 deletions

View File

@ -28,7 +28,6 @@ libimagstore = { version = "0.7.0", path = "../../../lib/core/libimagstore
libimagrt = { version = "0.7.0", path = "../../../lib/core/libimagrt" }
libimagerror = { version = "0.7.0", path = "../../../lib/core/libimagerror" }
libimagentryref = { version = "0.7.0", path = "../../../lib/entry/libimagentryref" }
libimagentrylist = { version = "0.7.0", path = "../../../lib/entry/libimagentrylist" }
libimaginteraction = { version = "0.7.0", path = "../../../lib/etc/libimaginteraction" }
libimagutil = { version = "0.7.0", path = "../../../lib/etc/libimagutil" }

View File

@ -39,7 +39,6 @@ extern crate libimagstore;
#[macro_use] extern crate libimagrt;
extern crate libimagentryref;
extern crate libimagerror;
extern crate libimagentrylist;
extern crate libimaginteraction;
extern crate libimagutil;

View File

@ -32,7 +32,6 @@ libimagstore = { version = "0.7.0", path = "../../../lib/core/libimagstore
libimagrt = { version = "0.7.0", path = "../../../lib/core/libimagrt" }
libimagdiary = { version = "0.7.0", path = "../../../lib/domain/libimagdiary" }
libimagentryedit = { version = "0.7.0", path = "../../../lib/entry/libimagentryedit" }
libimagentrylist = { version = "0.7.0", path = "../../../lib/entry/libimagentrylist" }
libimaginteraction = { version = "0.7.0", path = "../../../lib/etc/libimaginteraction" }
libimagutil = { version = "0.7.0", path = "../../../lib/etc/libimagutil" }
libimagtimeui = { version = "0.7.0", path = "../../../lib/etc/libimagtimeui" }

View File

@ -17,15 +17,14 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
use std::io::Write;
use libimagdiary::diary::Diary;
use libimagdiary::error::DiaryErrorKind as DEK;
use libimagdiary::error::ResultExt;
use libimagentrylist::listers::core::CoreLister;
use libimagentrylist::lister::Lister;
use libimagrt::runtime::Runtime;
use libimagstore::store::Entry;
use libimagutil::warn_exit::warn_exit;
use libimagerror::trace::MapErrTrace;
use libimagerror::io::ToExitCode;
use libimagerror::exit::ExitUnwrap;
use libimagutil::debug_result::*;
use util::get_diary_name;
@ -34,33 +33,27 @@ pub fn list(rt: &Runtime) {
let diaryname = get_diary_name(rt)
.unwrap_or_else(|| warn_exit("No diary selected. Use either the configuration file or the commandline option", 1));
fn entry_to_location_listing_string(e: &Entry) -> String {
e.get_location().clone()
.without_base()
.to_str()
.map_err_trace()
.unwrap_or(String::from("<<Path Parsing Error>>"))
}
let mut out = ::std::io::stdout();
Diary::entries(rt.store(), &diaryname)
.and_then(|es| {
debug!("Iterator for listing: {:?}", es);
let es = es
.filter_map(|entry| {
entry
.map_dbg(|e| format!("Filtering: {:?}", e))
.map_err_trace() // error tracing here
.ok() // so we can ignore errors here
})
.map(|e| e.into());
CoreLister::new(&entry_to_location_listing_string)
.list(es)
.chain_err(|| DEK::IOError)
})
.map_dbg_str("Ok")
.map_err_trace()
.ok();
.map_err_trace_exit_unwrap(1)
.filter_map(|entry| {
entry
.map_dbg(|e| format!("Filtering: {:?}", e))
.map_err_trace() // error tracing here
.ok() // so we can ignore errors here
})
.for_each(|e| {
writeln!(out, "{}", e
.get_location()
.clone()
.without_base()
.to_str()
.map_err_trace()
.unwrap_or(String::from("<<Path Parsing Error>>")))
.to_exit_code()
.unwrap_or_exit();
})
}

View File

@ -40,7 +40,6 @@ extern crate toml_query;
extern crate libimagdiary;
extern crate libimagentryedit;
extern crate libimagentrylist;
extern crate libimagerror;
extern crate libimaginteraction;
#[macro_use] extern crate libimagrt;

View File

@ -27,12 +27,12 @@ log = "0.3"
toml = "0.4"
toml-query = "0.6"
kairos = "0.1.0"
prettytable-rs = "0.6"
libimagerror = { version = "0.7.0", path = "../../../lib/core/libimagerror" }
libimagstore = { version = "0.7.0", path = "../../../lib/core/libimagstore" }
libimagrt = { version = "0.7.0", path = "../../../lib/core/libimagrt" }
libimagentryedit = { version = "0.7.0", path = "../../../lib/entry/libimagentryedit" }
libimagentrylist = { version = "0.7.0", path = "../../../lib/entry/libimagentrylist" }
libimaginteraction = { version = "0.7.0", path = "../../../lib/etc/libimaginteraction" }
libimagutil = { version = "0.7.0", path = "../../../lib/etc/libimagutil" }
libimagtimeui = { version = "0.7.0", path = "../../../lib/etc/libimagtimeui" }

View File

@ -38,18 +38,22 @@ extern crate toml;
extern crate toml_query;
extern crate kairos;
extern crate chrono;
extern crate prettytable;
extern crate libimaghabit;
extern crate libimagstore;
#[macro_use] extern crate libimagrt;
extern crate libimagerror;
extern crate libimagutil;
extern crate libimagentrylist;
extern crate libimaginteraction;
use std::io::Write;
use std::process::exit;
use prettytable::Table;
use prettytable::cell::Cell;
use prettytable::row::Row;
use libimagrt::runtime::Runtime;
use libimagrt::setup::generate_runtime_setup;
use libimagerror::trace::{MapErrTrace, trace_error};
@ -61,8 +65,6 @@ use libimaghabit::habit::HabitTemplate;
use libimagstore::store::FileLockEntry;
use libimagstore::store::Store;
use libimagstore::storeid::StoreId;
use libimagentrylist::listers::table::TableLister;
use libimagentrylist::lister::Lister;
use libimaginteraction::ask::ask_bool;
mod ui;
@ -312,17 +314,27 @@ fn today(rt: &Runtime, future: bool) {
v
}
fn lister_header() -> Vec<String> {
["Name", "Basedate", "Recurr", "Next Due", "Comment"]
.iter().map(|x| String::from(*x)).collect()
let header = ["#", "Name", "Basedate", "Recurr", "Next Due", "Comment"]
.iter()
.map(|s| Cell::new(s))
.collect::<Vec<Cell>>();
let mut table = Table::new();
table.set_titles(Row::new(header));
let mut empty = true;
for (i, e) in relevant.into_iter().enumerate() {
let mut v = vec![format!("{}", i)];
let mut list = lister_fn(&e);
v.append(&mut list);
table.add_row(v.iter().map(|s| Cell::new(s)).collect());
empty = false;
}
TableLister::new(lister_fn)
.with_header(lister_header())
.with_idx(true)
.print_empty(false)
.list(relevant.into_iter())
.map_err_trace_exit_unwrap(1);
if !empty {
let mut out = ::std::io::stdout();
let _ = table.print(&mut out).to_exit_code().unwrap_or_exit();
}
}
}
@ -342,11 +354,16 @@ fn list(rt: &Runtime) {
v
}
fn lister_header() -> Vec<String> {
["Name", "Basedate", "Recurr", "Comment", "Next Due"].iter().map(|x| String::from(*x)).collect()
}
let header = ["#", "Name", "Basedate", "Recurr", "Comment", "Next Due"]
.iter()
.map(|s| Cell::new(s))
.collect::<Vec<Cell>>();
let iter = rt
let mut empty = true;
let mut table = Table::new();
table.set_titles(Row::new(header));
let _ = rt
.store()
.all_habit_templates()
.map_err_trace_exit_unwrap(1)
@ -360,15 +377,20 @@ fn list(rt: &Runtime) {
trace_error(&e);
None
},
})
.enumerate()
.for_each(|(i, e)| {
let mut v = vec![format!("{}", i)];
let mut list = lister_fn(&e);
v.append(&mut list);
table.add_row(v.iter().map(|s| Cell::new(s)).collect());
empty = false;
});
TableLister::new(lister_fn)
.with_header(lister_header())
.with_idx(true)
.print_empty(false)
.list(iter)
.map_err_trace_exit_unwrap(1);
if !empty {
let mut out = ::std::io::stdout();
let _ = table.print(&mut out).to_exit_code().unwrap_or_exit();
}
}
fn show(rt: &Runtime) {
@ -378,9 +400,6 @@ fn show(rt: &Runtime) {
.map(String::from)
.unwrap(); // safe by clap
fn instance_lister_header() -> Vec<String> {
["Date", "Comment"].iter().map(|x| String::from(*x)).collect()
}
fn instance_lister_fn(i: &FileLockEntry) -> Vec<String> {
use libimagutil::date::date_to_string;
@ -393,6 +412,13 @@ fn show(rt: &Runtime) {
}
let mut out = ::std::io::stdout();
let header = ["#", "Date", "Comment"]
.iter()
.map(|s| Cell::new(s))
.collect::<Vec<Cell>>();
let mut table = Table::new();
table.set_titles(Row::new(header));
let _ = rt
.store()
@ -417,20 +443,27 @@ fn show(rt: &Runtime) {
.to_exit_code()
.unwrap_or_exit();
let instances_iter = habit
let mut empty = true;
let _ = habit
.linked_instances()
.map_err_trace_exit_unwrap(1)
.filter_map(|instance_id| {
debug!("Getting: {:?}", instance_id);
rt.store().get(instance_id).map_err_trace_exit_unwrap(1)
})
.enumerate()
.for_each(|(i, e)| {
let mut v = vec![format!("{}", i)];
let mut instances = instance_lister_fn(&e);
v.append(&mut instances);
table.add_row(v.iter().map(|s| Cell::new(s)).collect());
empty = false;
});
TableLister::new(instance_lister_fn)
.with_header(instance_lister_header())
.with_idx(true)
.print_empty(false)
.list(instances_iter)
.map_err_trace_exit_unwrap(1);
if !empty {
let mut out = ::std::io::stdout();
let _ = table.print(&mut out).to_exit_code().unwrap_or_exit();
}
})
.collect::<Vec<_>>();
}

View File

@ -28,7 +28,6 @@ error-chain = "0.11"
libimagstore = { version = "0.7.0", path = "../../../lib/core/libimagstore" }
libimagerror = { version = "0.7.0", path = "../../../lib/core/libimagerror" }
libimagentrylist = { version = "0.7.0", path = "../../../lib/entry/libimagentrylist" }
libimagentryutil = { version = "0.7.0", path = "../../../lib/entry/libimagentryutil" }
[dependencies.rust-crypto]

View File

@ -42,7 +42,6 @@ extern crate toml_query;
#[macro_use] extern crate libimagstore;
extern crate libimagerror;
extern crate libimagentrylist;
#[macro_use] extern crate libimagentryutil;
#[macro_use] extern crate error_chain;