Merge pull request #1298 from matthiasbeyer/remove-libimagentrylist
Remove libimagentrylist
This commit is contained in:
commit
9c98d8f56e
24 changed files with 93 additions and 593 deletions
|
@ -42,7 +42,6 @@ members = [
|
||||||
"lib/entry/libimagentryfilter",
|
"lib/entry/libimagentryfilter",
|
||||||
"lib/entry/libimagentrygps",
|
"lib/entry/libimagentrygps",
|
||||||
"lib/entry/libimagentrylink",
|
"lib/entry/libimagentrylink",
|
||||||
"lib/entry/libimagentrylist",
|
|
||||||
"lib/entry/libimagentrymarkdown",
|
"lib/entry/libimagentrymarkdown",
|
||||||
"lib/entry/libimagentryref",
|
"lib/entry/libimagentryref",
|
||||||
"lib/entry/libimagentrytag",
|
"lib/entry/libimagentrytag",
|
||||||
|
|
|
@ -28,7 +28,6 @@ libimagstore = { version = "0.7.0", path = "../../../lib/core/libimagstore
|
||||||
libimagrt = { version = "0.7.0", path = "../../../lib/core/libimagrt" }
|
libimagrt = { version = "0.7.0", path = "../../../lib/core/libimagrt" }
|
||||||
libimagerror = { version = "0.7.0", path = "../../../lib/core/libimagerror" }
|
libimagerror = { version = "0.7.0", path = "../../../lib/core/libimagerror" }
|
||||||
libimagentryref = { version = "0.7.0", path = "../../../lib/entry/libimagentryref" }
|
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" }
|
libimaginteraction = { version = "0.7.0", path = "../../../lib/etc/libimaginteraction" }
|
||||||
libimagutil = { version = "0.7.0", path = "../../../lib/etc/libimagutil" }
|
libimagutil = { version = "0.7.0", path = "../../../lib/etc/libimagutil" }
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,6 @@ extern crate libimagstore;
|
||||||
#[macro_use] extern crate libimagrt;
|
#[macro_use] extern crate libimagrt;
|
||||||
extern crate libimagentryref;
|
extern crate libimagentryref;
|
||||||
extern crate libimagerror;
|
extern crate libimagerror;
|
||||||
extern crate libimagentrylist;
|
|
||||||
extern crate libimaginteraction;
|
extern crate libimaginteraction;
|
||||||
extern crate libimagutil;
|
extern crate libimagutil;
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,6 @@ libimagstore = { version = "0.7.0", path = "../../../lib/core/libimagstore
|
||||||
libimagrt = { version = "0.7.0", path = "../../../lib/core/libimagrt" }
|
libimagrt = { version = "0.7.0", path = "../../../lib/core/libimagrt" }
|
||||||
libimagdiary = { version = "0.7.0", path = "../../../lib/domain/libimagdiary" }
|
libimagdiary = { version = "0.7.0", path = "../../../lib/domain/libimagdiary" }
|
||||||
libimagentryedit = { version = "0.7.0", path = "../../../lib/entry/libimagentryedit" }
|
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" }
|
libimaginteraction = { version = "0.7.0", path = "../../../lib/etc/libimaginteraction" }
|
||||||
libimagutil = { version = "0.7.0", path = "../../../lib/etc/libimagutil" }
|
libimagutil = { version = "0.7.0", path = "../../../lib/etc/libimagutil" }
|
||||||
libimagtimeui = { version = "0.7.0", path = "../../../lib/etc/libimagtimeui" }
|
libimagtimeui = { version = "0.7.0", path = "../../../lib/etc/libimagtimeui" }
|
||||||
|
|
|
@ -17,15 +17,14 @@
|
||||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
//
|
//
|
||||||
|
|
||||||
|
use std::io::Write;
|
||||||
|
|
||||||
use libimagdiary::diary::Diary;
|
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 libimagrt::runtime::Runtime;
|
||||||
use libimagstore::store::Entry;
|
|
||||||
use libimagutil::warn_exit::warn_exit;
|
use libimagutil::warn_exit::warn_exit;
|
||||||
use libimagerror::trace::MapErrTrace;
|
use libimagerror::trace::MapErrTrace;
|
||||||
|
use libimagerror::io::ToExitCode;
|
||||||
|
use libimagerror::exit::ExitUnwrap;
|
||||||
use libimagutil::debug_result::*;
|
use libimagutil::debug_result::*;
|
||||||
|
|
||||||
use util::get_diary_name;
|
use util::get_diary_name;
|
||||||
|
@ -34,33 +33,27 @@ pub fn list(rt: &Runtime) {
|
||||||
let diaryname = get_diary_name(rt)
|
let diaryname = get_diary_name(rt)
|
||||||
.unwrap_or_else(|| warn_exit("No diary selected. Use either the configuration file or the commandline option", 1));
|
.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 {
|
let mut out = ::std::io::stdout();
|
||||||
e.get_location().clone()
|
|
||||||
.without_base()
|
|
||||||
.to_str()
|
|
||||||
.map_err_trace()
|
|
||||||
.unwrap_or(String::from("<<Path Parsing Error>>"))
|
|
||||||
}
|
|
||||||
|
|
||||||
Diary::entries(rt.store(), &diaryname)
|
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_dbg_str("Ok")
|
||||||
.map_err_trace()
|
.map_err_trace_exit_unwrap(1)
|
||||||
.ok();
|
.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();
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,6 @@ extern crate toml_query;
|
||||||
|
|
||||||
extern crate libimagdiary;
|
extern crate libimagdiary;
|
||||||
extern crate libimagentryedit;
|
extern crate libimagentryedit;
|
||||||
extern crate libimagentrylist;
|
|
||||||
extern crate libimagerror;
|
extern crate libimagerror;
|
||||||
extern crate libimaginteraction;
|
extern crate libimaginteraction;
|
||||||
#[macro_use] extern crate libimagrt;
|
#[macro_use] extern crate libimagrt;
|
||||||
|
|
|
@ -27,12 +27,12 @@ log = "0.3"
|
||||||
toml = "0.4"
|
toml = "0.4"
|
||||||
toml-query = "0.6"
|
toml-query = "0.6"
|
||||||
kairos = "0.1.0"
|
kairos = "0.1.0"
|
||||||
|
prettytable-rs = "0.6"
|
||||||
|
|
||||||
libimagerror = { version = "0.7.0", path = "../../../lib/core/libimagerror" }
|
libimagerror = { version = "0.7.0", path = "../../../lib/core/libimagerror" }
|
||||||
libimagstore = { version = "0.7.0", path = "../../../lib/core/libimagstore" }
|
libimagstore = { version = "0.7.0", path = "../../../lib/core/libimagstore" }
|
||||||
libimagrt = { version = "0.7.0", path = "../../../lib/core/libimagrt" }
|
libimagrt = { version = "0.7.0", path = "../../../lib/core/libimagrt" }
|
||||||
libimagentryedit = { version = "0.7.0", path = "../../../lib/entry/libimagentryedit" }
|
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" }
|
libimaginteraction = { version = "0.7.0", path = "../../../lib/etc/libimaginteraction" }
|
||||||
libimagutil = { version = "0.7.0", path = "../../../lib/etc/libimagutil" }
|
libimagutil = { version = "0.7.0", path = "../../../lib/etc/libimagutil" }
|
||||||
libimagtimeui = { version = "0.7.0", path = "../../../lib/etc/libimagtimeui" }
|
libimagtimeui = { version = "0.7.0", path = "../../../lib/etc/libimagtimeui" }
|
||||||
|
|
|
@ -38,18 +38,22 @@ extern crate toml;
|
||||||
extern crate toml_query;
|
extern crate toml_query;
|
||||||
extern crate kairos;
|
extern crate kairos;
|
||||||
extern crate chrono;
|
extern crate chrono;
|
||||||
|
extern crate prettytable;
|
||||||
|
|
||||||
extern crate libimaghabit;
|
extern crate libimaghabit;
|
||||||
extern crate libimagstore;
|
extern crate libimagstore;
|
||||||
#[macro_use] extern crate libimagrt;
|
#[macro_use] extern crate libimagrt;
|
||||||
extern crate libimagerror;
|
extern crate libimagerror;
|
||||||
extern crate libimagutil;
|
extern crate libimagutil;
|
||||||
extern crate libimagentrylist;
|
|
||||||
extern crate libimaginteraction;
|
extern crate libimaginteraction;
|
||||||
|
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::process::exit;
|
use std::process::exit;
|
||||||
|
|
||||||
|
use prettytable::Table;
|
||||||
|
use prettytable::cell::Cell;
|
||||||
|
use prettytable::row::Row;
|
||||||
|
|
||||||
use libimagrt::runtime::Runtime;
|
use libimagrt::runtime::Runtime;
|
||||||
use libimagrt::setup::generate_runtime_setup;
|
use libimagrt::setup::generate_runtime_setup;
|
||||||
use libimagerror::trace::{MapErrTrace, trace_error};
|
use libimagerror::trace::{MapErrTrace, trace_error};
|
||||||
|
@ -61,8 +65,6 @@ use libimaghabit::habit::HabitTemplate;
|
||||||
use libimagstore::store::FileLockEntry;
|
use libimagstore::store::FileLockEntry;
|
||||||
use libimagstore::store::Store;
|
use libimagstore::store::Store;
|
||||||
use libimagstore::storeid::StoreId;
|
use libimagstore::storeid::StoreId;
|
||||||
use libimagentrylist::listers::table::TableLister;
|
|
||||||
use libimagentrylist::lister::Lister;
|
|
||||||
use libimaginteraction::ask::ask_bool;
|
use libimaginteraction::ask::ask_bool;
|
||||||
|
|
||||||
mod ui;
|
mod ui;
|
||||||
|
@ -312,17 +314,27 @@ fn today(rt: &Runtime, future: bool) {
|
||||||
v
|
v
|
||||||
}
|
}
|
||||||
|
|
||||||
fn lister_header() -> Vec<String> {
|
let header = ["#", "Name", "Basedate", "Recurr", "Next Due", "Comment"]
|
||||||
["Name", "Basedate", "Recurr", "Next Due", "Comment"]
|
.iter()
|
||||||
.iter().map(|x| String::from(*x)).collect()
|
.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)
|
if !empty {
|
||||||
.with_header(lister_header())
|
let mut out = ::std::io::stdout();
|
||||||
.with_idx(true)
|
let _ = table.print(&mut out).to_exit_code().unwrap_or_exit();
|
||||||
.print_empty(false)
|
}
|
||||||
.list(relevant.into_iter())
|
|
||||||
.map_err_trace_exit_unwrap(1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -342,11 +354,16 @@ fn list(rt: &Runtime) {
|
||||||
v
|
v
|
||||||
}
|
}
|
||||||
|
|
||||||
fn lister_header() -> Vec<String> {
|
let header = ["#", "Name", "Basedate", "Recurr", "Comment", "Next Due"]
|
||||||
["Name", "Basedate", "Recurr", "Comment", "Next Due"].iter().map(|x| String::from(*x)).collect()
|
.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()
|
.store()
|
||||||
.all_habit_templates()
|
.all_habit_templates()
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap(1)
|
||||||
|
@ -360,15 +377,20 @@ fn list(rt: &Runtime) {
|
||||||
trace_error(&e);
|
trace_error(&e);
|
||||||
None
|
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;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if !empty {
|
||||||
TableLister::new(lister_fn)
|
let mut out = ::std::io::stdout();
|
||||||
.with_header(lister_header())
|
let _ = table.print(&mut out).to_exit_code().unwrap_or_exit();
|
||||||
.with_idx(true)
|
}
|
||||||
.print_empty(false)
|
|
||||||
.list(iter)
|
|
||||||
.map_err_trace_exit_unwrap(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn show(rt: &Runtime) {
|
fn show(rt: &Runtime) {
|
||||||
|
@ -378,9 +400,6 @@ fn show(rt: &Runtime) {
|
||||||
.map(String::from)
|
.map(String::from)
|
||||||
.unwrap(); // safe by clap
|
.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> {
|
fn instance_lister_fn(i: &FileLockEntry) -> Vec<String> {
|
||||||
use libimagutil::date::date_to_string;
|
use libimagutil::date::date_to_string;
|
||||||
|
@ -393,6 +412,13 @@ fn show(rt: &Runtime) {
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut out = ::std::io::stdout();
|
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
|
let _ = rt
|
||||||
.store()
|
.store()
|
||||||
|
@ -417,20 +443,27 @@ fn show(rt: &Runtime) {
|
||||||
.to_exit_code()
|
.to_exit_code()
|
||||||
.unwrap_or_exit();
|
.unwrap_or_exit();
|
||||||
|
|
||||||
let instances_iter = habit
|
let mut empty = true;
|
||||||
|
let _ = habit
|
||||||
.linked_instances()
|
.linked_instances()
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap(1)
|
||||||
.filter_map(|instance_id| {
|
.filter_map(|instance_id| {
|
||||||
debug!("Getting: {:?}", instance_id);
|
debug!("Getting: {:?}", instance_id);
|
||||||
rt.store().get(instance_id).map_err_trace_exit_unwrap(1)
|
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)
|
if !empty {
|
||||||
.with_header(instance_lister_header())
|
let mut out = ::std::io::stdout();
|
||||||
.with_idx(true)
|
let _ = table.print(&mut out).to_exit_code().unwrap_or_exit();
|
||||||
.print_empty(false)
|
}
|
||||||
.list(instances_iter)
|
|
||||||
.map_err_trace_exit_unwrap(1);
|
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +0,0 @@
|
||||||
## libimagentrylist
|
|
||||||
|
|
||||||
Library for listing entries in different manner.
|
|
||||||
|
|
||||||
This includes:
|
|
||||||
|
|
||||||
* Plain one-line-one-entry-path listing
|
|
||||||
* Tree listing by submodule
|
|
||||||
* Listing with metadata
|
|
||||||
* One-line-one-entry
|
|
||||||
* ASCII-Table
|
|
||||||
|
|
|
@ -30,6 +30,9 @@ This section contains the changelog from the last release to the next release.
|
||||||
but users of the library really should be be able to put entries under
|
but users of the library really should be be able to put entries under
|
||||||
custom collections.
|
custom collections.
|
||||||
* `imag store ids` was replaced by `imag ids`.
|
* `imag store ids` was replaced by `imag ids`.
|
||||||
|
* `libimagentrylist` was removed. Its functionality was inconvenient to use
|
||||||
|
and ugly to implement. Its API was cumbersome.
|
||||||
|
Listing of entries shall be implemented without it.
|
||||||
* Minor changes
|
* Minor changes
|
||||||
* A license-checker was included into the CI setup, which checks whether all
|
* A license-checker was included into the CI setup, which checks whether all
|
||||||
".rs"-files have the license header at the top of the file
|
".rs"-files have the license header at the top of the file
|
||||||
|
|
|
@ -199,11 +199,6 @@ destinations = []
|
||||||
level = "debug"
|
level = "debug"
|
||||||
enabled = true
|
enabled = true
|
||||||
|
|
||||||
[imag.logging.modules.libimagentrylist]
|
|
||||||
destinations = []
|
|
||||||
level = "debug"
|
|
||||||
enabled = true
|
|
||||||
|
|
||||||
[imag.logging.modules.libimagentryedit]
|
[imag.logging.modules.libimagentryedit]
|
||||||
destinations = []
|
destinations = []
|
||||||
level = "debug"
|
level = "debug"
|
||||||
|
|
|
@ -1,35 +0,0 @@
|
||||||
[package]
|
|
||||||
name = "libimagentrylist"
|
|
||||||
version = "0.7.0"
|
|
||||||
authors = ["Matthias Beyer <mail@beyermatthias.de>"]
|
|
||||||
|
|
||||||
description = "Library for the imag core distribution"
|
|
||||||
|
|
||||||
keywords = ["imag", "PIM", "personal", "information", "management"]
|
|
||||||
readme = "../../../README.md"
|
|
||||||
license = "LGPL-2.1"
|
|
||||||
|
|
||||||
documentation = "https://matthiasbeyer.github.io/imag/imag_documentation/index.html"
|
|
||||||
repository = "https://github.com/matthiasbeyer/imag"
|
|
||||||
homepage = "http://imag-pim.org"
|
|
||||||
|
|
||||||
[badges]
|
|
||||||
travis-ci = { repository = "matthiasbeyer/imag" }
|
|
||||||
is-it-maintained-issue-resolution = { repository = "matthiasbeyer/imag" }
|
|
||||||
is-it-maintained-open-issues = { repository = "matthiasbeyer/imag" }
|
|
||||||
maintenance = { status = "actively-developed" }
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
log = "0.4.0"
|
|
||||||
prettytable-rs = "0.6.*"
|
|
||||||
error-chain = "0.11"
|
|
||||||
|
|
||||||
libimagstore = { version = "0.7.0", path = "../../../lib/core/libimagstore" }
|
|
||||||
libimagerror = { version = "0.7.0", path = "../../../lib/core/libimagerror" }
|
|
||||||
libimagutil = { version = "0.7.0", path = "../../../lib/etc/libimagutil" }
|
|
||||||
|
|
||||||
[dependencies.clap]
|
|
||||||
version = ">=2.29"
|
|
||||||
default-features = false
|
|
||||||
features = ["color", "suggestions"]
|
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
../../../doc/src/05100-lib-entrylist.md
|
|
|
@ -1,53 +0,0 @@
|
||||||
//
|
|
||||||
// imag - the personal information management suite for the commandline
|
|
||||||
// Copyright (C) 2015-2018 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
|
|
||||||
//
|
|
||||||
|
|
||||||
error_chain! {
|
|
||||||
types {
|
|
||||||
ListError, ListErrorKind, ResultExt, Result;
|
|
||||||
}
|
|
||||||
|
|
||||||
errors {
|
|
||||||
IOError {
|
|
||||||
description("IO Error")
|
|
||||||
display("IO Error")
|
|
||||||
}
|
|
||||||
|
|
||||||
FormatError {
|
|
||||||
description("FormatError")
|
|
||||||
display("FormatError")
|
|
||||||
}
|
|
||||||
|
|
||||||
EntryError {
|
|
||||||
description("EntryError")
|
|
||||||
display("EntryError")
|
|
||||||
}
|
|
||||||
|
|
||||||
IterationError {
|
|
||||||
description("IterationError")
|
|
||||||
display("IterationError")
|
|
||||||
}
|
|
||||||
|
|
||||||
CLIError {
|
|
||||||
description("No CLI subcommand for listing entries")
|
|
||||||
display("No CLI subcommand for listing entries")
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,50 +0,0 @@
|
||||||
//
|
|
||||||
// imag - the personal information management suite for the commandline
|
|
||||||
// Copyright (C) 2015-2018 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
|
|
||||||
//
|
|
||||||
|
|
||||||
#![recursion_limit="256"]
|
|
||||||
|
|
||||||
#![deny(
|
|
||||||
dead_code,
|
|
||||||
non_camel_case_types,
|
|
||||||
non_snake_case,
|
|
||||||
path_statements,
|
|
||||||
trivial_numeric_casts,
|
|
||||||
unstable_features,
|
|
||||||
unused_allocation,
|
|
||||||
unused_import_braces,
|
|
||||||
unused_imports,
|
|
||||||
unused_must_use,
|
|
||||||
unused_mut,
|
|
||||||
unused_qualifications,
|
|
||||||
while_true,
|
|
||||||
)]
|
|
||||||
|
|
||||||
extern crate clap;
|
|
||||||
#[macro_use] extern crate log;
|
|
||||||
extern crate prettytable;
|
|
||||||
#[macro_use] extern crate error_chain;
|
|
||||||
|
|
||||||
extern crate libimagstore;
|
|
||||||
extern crate libimagutil;
|
|
||||||
extern crate libimagerror;
|
|
||||||
|
|
||||||
pub mod error;
|
|
||||||
pub mod lister;
|
|
||||||
pub mod listers;
|
|
||||||
|
|
|
@ -1,29 +0,0 @@
|
||||||
//
|
|
||||||
// imag - the personal information management suite for the commandline
|
|
||||||
// Copyright (C) 2015-2018 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
|
|
||||||
//
|
|
||||||
|
|
||||||
use libimagstore::store::FileLockEntry;
|
|
||||||
|
|
||||||
use error::Result;
|
|
||||||
|
|
||||||
pub trait Lister : Sized {
|
|
||||||
|
|
||||||
fn list<'a, I: Iterator<Item = FileLockEntry<'a>>>(&self, entries: I) -> Result<()>;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,65 +0,0 @@
|
||||||
//
|
|
||||||
// imag - the personal information management suite for the commandline
|
|
||||||
// Copyright (C) 2015-2018 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
|
|
||||||
//
|
|
||||||
|
|
||||||
use std::io::stdout;
|
|
||||||
use std::io::Write;
|
|
||||||
|
|
||||||
use lister::Lister;
|
|
||||||
use error::Result;
|
|
||||||
use error::ResultExt;
|
|
||||||
|
|
||||||
use libimagstore::store::FileLockEntry;
|
|
||||||
use libimagstore::store::Entry;
|
|
||||||
|
|
||||||
pub struct CoreLister<T: Fn(&Entry) -> String> {
|
|
||||||
lister: Box<T>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T: Fn(&Entry) -> String> CoreLister<T> {
|
|
||||||
|
|
||||||
pub fn new(lister: T) -> CoreLister<T> {
|
|
||||||
CoreLister {
|
|
||||||
lister: Box::new(lister),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T: Fn(&Entry) -> String> Lister for CoreLister<T> {
|
|
||||||
|
|
||||||
fn list<'b, I: Iterator<Item = FileLockEntry<'b>>>(&self, entries: I) -> Result<()> {
|
|
||||||
use error::ListErrorKind as LEK;
|
|
||||||
|
|
||||||
debug!("Called list()");
|
|
||||||
let (r, n) = entries
|
|
||||||
.fold((Ok(()), 0), |(accu, i), entry| {
|
|
||||||
debug!("fold({:?}, {:?})", accu, entry);
|
|
||||||
let r = accu.and_then(|_| {
|
|
||||||
debug!("Listing Entry: {:?}", entry);
|
|
||||||
write!(stdout(), "{:?}\n", (self.lister)(&entry))
|
|
||||||
.chain_err(|| LEK::FormatError)
|
|
||||||
});
|
|
||||||
(r, i + 1)
|
|
||||||
});
|
|
||||||
debug!("Iterated over {} entries", n);
|
|
||||||
r
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,56 +0,0 @@
|
||||||
//
|
|
||||||
// imag - the personal information management suite for the commandline
|
|
||||||
// Copyright (C) 2015-2018 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
|
|
||||||
//
|
|
||||||
|
|
||||||
use std::io::stdout;
|
|
||||||
use std::io::Write;
|
|
||||||
|
|
||||||
use lister::Lister;
|
|
||||||
use error::Result;
|
|
||||||
use error::ResultExt;
|
|
||||||
|
|
||||||
use libimagstore::store::FileLockEntry;
|
|
||||||
|
|
||||||
pub struct LineLister<'a> {
|
|
||||||
unknown_output: &'a str,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> LineLister<'a> {
|
|
||||||
|
|
||||||
pub fn new(unknown_output: &'a str) -> LineLister<'a> {
|
|
||||||
LineLister {
|
|
||||||
unknown_output: unknown_output,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> Lister for LineLister<'a> {
|
|
||||||
|
|
||||||
fn list<'b, I: Iterator<Item = FileLockEntry<'b>>>(&self, entries: I) -> Result<()> {
|
|
||||||
use error::ListErrorKind as LEK;
|
|
||||||
|
|
||||||
for entry in entries {
|
|
||||||
let s = entry.get_location().to_str().unwrap_or(String::from(self.unknown_output));
|
|
||||||
write!(stdout(), "{:?}\n", s).chain_err(|| LEK::FormatError)?
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,23 +0,0 @@
|
||||||
//
|
|
||||||
// imag - the personal information management suite for the commandline
|
|
||||||
// Copyright (C) 2015-2018 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
|
|
||||||
//
|
|
||||||
|
|
||||||
pub mod core;
|
|
||||||
pub mod line;
|
|
||||||
pub mod path;
|
|
||||||
pub mod table;
|
|
|
@ -1,64 +0,0 @@
|
||||||
//
|
|
||||||
// imag - the personal information management suite for the commandline
|
|
||||||
// Copyright (C) 2015-2018 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
|
|
||||||
//
|
|
||||||
|
|
||||||
use std::io::stdout;
|
|
||||||
use std::io::Write;
|
|
||||||
|
|
||||||
use lister::Lister;
|
|
||||||
use error::Result;
|
|
||||||
use error::ResultExt;
|
|
||||||
|
|
||||||
use libimagstore::store::FileLockEntry;
|
|
||||||
|
|
||||||
pub struct PathLister {
|
|
||||||
absolute: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl PathLister {
|
|
||||||
|
|
||||||
pub fn new(absolute: bool) -> PathLister {
|
|
||||||
PathLister {
|
|
||||||
absolute: absolute,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Lister for PathLister {
|
|
||||||
|
|
||||||
fn list<'a, I: Iterator<Item = FileLockEntry<'a>>>(&self, entries: I) -> Result<()> {
|
|
||||||
use error::ListErrorKind as LEK;
|
|
||||||
|
|
||||||
for entry in entries {
|
|
||||||
let pb = entry.get_location().clone();
|
|
||||||
let pb = pb.into_pathbuf().chain_err(|| LEK::FormatError)?;
|
|
||||||
let pb = if self.absolute {
|
|
||||||
pb.canonicalize().chain_err(|| LEK::FormatError)?
|
|
||||||
} else {
|
|
||||||
pb.into()
|
|
||||||
};
|
|
||||||
|
|
||||||
write!(stdout(), "{:?}\n", pb).chain_err(|| LEK::FormatError)?
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,128 +0,0 @@
|
||||||
//
|
|
||||||
// imag - the personal information management suite for the commandline
|
|
||||||
// Copyright (C) 2015-2018 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
|
|
||||||
//
|
|
||||||
|
|
||||||
use std::io::stdout;
|
|
||||||
|
|
||||||
use lister::Lister;
|
|
||||||
use error::Result;
|
|
||||||
use error::ResultExt;
|
|
||||||
|
|
||||||
use libimagstore::store::FileLockEntry;
|
|
||||||
|
|
||||||
use prettytable::Table;
|
|
||||||
use prettytable::cell::Cell;
|
|
||||||
use prettytable::row::Row;
|
|
||||||
|
|
||||||
pub struct TableLister<F: Fn(&FileLockEntry) -> Vec<String>> {
|
|
||||||
line_generator: F,
|
|
||||||
header: Option<Vec<String>>,
|
|
||||||
|
|
||||||
with_idx: bool,
|
|
||||||
print_empty: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<F: Fn(&FileLockEntry) -> Vec<String>> TableLister<F> {
|
|
||||||
|
|
||||||
pub fn new(gen: F) -> TableLister<F> {
|
|
||||||
TableLister {
|
|
||||||
line_generator: gen,
|
|
||||||
header: None,
|
|
||||||
with_idx: true,
|
|
||||||
print_empty: false,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn with_header(mut self, hdr: Vec<String>) -> TableLister<F> {
|
|
||||||
self.header = Some(hdr);
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn with_idx(mut self, b: bool) -> TableLister<F> {
|
|
||||||
self.with_idx = b;
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn print_empty(mut self, b: bool) -> TableLister<F> {
|
|
||||||
self.print_empty = b;
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<F: Fn(&FileLockEntry) -> Vec<String>> Lister for TableLister<F> {
|
|
||||||
|
|
||||||
fn list<'b, I: Iterator<Item = FileLockEntry<'b>>>(&self, entries: I) -> Result<()> {
|
|
||||||
use error::ListErrorKind as LEK;
|
|
||||||
use error::ListError as LE;
|
|
||||||
|
|
||||||
let mut table = Table::new();
|
|
||||||
let mut header_len : Option<usize> = None;
|
|
||||||
match self.header {
|
|
||||||
Some(ref s) => {
|
|
||||||
debug!("We have a header... preparing");
|
|
||||||
let mut cells : Vec<Cell> = s.iter().map(|s| Cell::new(s)).collect();
|
|
||||||
if self.with_idx {
|
|
||||||
cells.insert(0, Cell::new("#"));
|
|
||||||
}
|
|
||||||
table.set_titles(Row::new(cells));
|
|
||||||
header_len = Some(s.len());
|
|
||||||
},
|
|
||||||
None => {
|
|
||||||
debug!("No header for table found... continuing without");
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut entries_added = 0;
|
|
||||||
|
|
||||||
entries.enumerate().fold(Ok(table), |table, (i, entry)| {
|
|
||||||
table.and_then(|mut table| {
|
|
||||||
let mut v = (self.line_generator)(&entry);
|
|
||||||
{
|
|
||||||
let v_len = v.len();
|
|
||||||
if header_len.is_none() {
|
|
||||||
header_len = Some(v_len);
|
|
||||||
}
|
|
||||||
if header_len.map(|l| v_len > l).unwrap_or(false) {
|
|
||||||
return Err(LE::from_kind(LEK::FormatError));
|
|
||||||
}
|
|
||||||
while header_len.map(|l| v.len() != l).unwrap_or(false) {
|
|
||||||
v.push(String::from(""));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if self.with_idx {
|
|
||||||
v.insert(0, format!("{}", i));
|
|
||||||
}
|
|
||||||
|
|
||||||
table.add_row(v.iter().map(|s| Cell::new(s)).collect());
|
|
||||||
entries_added += 1;
|
|
||||||
Ok(table)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
.and_then(|tbl| {
|
|
||||||
if entries_added != 0 && !self.print_empty {
|
|
||||||
let mut io = stdout();
|
|
||||||
tbl.print(&mut io).chain_err(|| LEK::IOError)
|
|
||||||
} else {
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -28,7 +28,6 @@ error-chain = "0.11"
|
||||||
|
|
||||||
libimagstore = { version = "0.7.0", path = "../../../lib/core/libimagstore" }
|
libimagstore = { version = "0.7.0", path = "../../../lib/core/libimagstore" }
|
||||||
libimagerror = { version = "0.7.0", path = "../../../lib/core/libimagerror" }
|
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" }
|
libimagentryutil = { version = "0.7.0", path = "../../../lib/entry/libimagentryutil" }
|
||||||
|
|
||||||
[dependencies.rust-crypto]
|
[dependencies.rust-crypto]
|
||||||
|
|
|
@ -42,7 +42,6 @@ extern crate toml_query;
|
||||||
|
|
||||||
#[macro_use] extern crate libimagstore;
|
#[macro_use] extern crate libimagstore;
|
||||||
extern crate libimagerror;
|
extern crate libimagerror;
|
||||||
extern crate libimagentrylist;
|
|
||||||
#[macro_use] extern crate libimagentryutil;
|
#[macro_use] extern crate libimagentryutil;
|
||||||
#[macro_use] extern crate error_chain;
|
#[macro_use] extern crate error_chain;
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,6 @@ CRATES=(
|
||||||
./lib/entry/libimagentrytag
|
./lib/entry/libimagentrytag
|
||||||
./lib/entry/libimagentryfilter
|
./lib/entry/libimagentryfilter
|
||||||
./lib/entry/libimagentrygps
|
./lib/entry/libimagentrygps
|
||||||
./lib/entry/libimagentrylist
|
|
||||||
./lib/entry/libimagentryedit
|
./lib/entry/libimagentryedit
|
||||||
./lib/entry/libimagentryview
|
./lib/entry/libimagentryview
|
||||||
./lib/entry/libimagentrydatetime
|
./lib/entry/libimagentrydatetime
|
||||||
|
|
Loading…
Reference in a new issue