summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bin/core/imag-grep/src/main.rs1
-rw-r--r--bin/core/imag-ids/Cargo.toml2
-rw-r--r--bin/core/imag-ids/src/main.rs34
-rw-r--r--bin/domain/imag-diary/src/list.rs28
-rw-r--r--lib/domain/libimagdiary/src/viewer.rs16
-rw-r--r--lib/entry/libimagentrylink/src/internal.rs1
-rw-r--r--lib/entry/libimagentryref/src/refstore.rs4
7 files changed, 67 insertions, 19 deletions
diff --git a/bin/core/imag-grep/src/main.rs b/bin/core/imag-grep/src/main.rs
index 1f97e4a..223849c 100644
--- a/bin/core/imag-grep/src/main.rs
+++ b/bin/core/imag-grep/src/main.rs
@@ -120,6 +120,7 @@ fn show(rt: &Runtime, e: &Entry, re: &Regex, opts: &Options, count: &mut usize)
}
let _ = writeln!(rt.stdout(), "").to_exit_code().unwrap_or_exit();
+ *count += 1;
}
}
diff --git a/bin/core/imag-ids/Cargo.toml b/bin/core/imag-ids/Cargo.toml
index 0e9345c..519e708 100644
--- a/bin/core/imag-ids/Cargo.toml
+++ b/bin/core/imag-ids/Cargo.toml
@@ -22,6 +22,8 @@ is-it-maintained-open-issues = { repository = "matthiasbeyer/imag" }
maintenance = { status = "actively-developed" }
[dependencies]
+filters = "0.2"
+
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" }
diff --git a/bin/core/imag-ids/src/main.rs b/bin/core/imag-ids/src/main.rs
index 30e0c49..5dada73 100644
--- a/bin/core/imag-ids/src/main.rs
+++ b/bin/core/imag-ids/src/main.rs
@@ -33,6 +33,7 @@
)]
extern crate clap;
+extern crate filters;
extern crate libimagerror;
extern crate libimagstore;
@@ -40,12 +41,14 @@ extern crate libimagstore;
use std::io::Write;
+use filters::filter::Filter;
use clap::{Arg, App};
use libimagrt::setup::generate_runtime_setup;
use libimagerror::trace::MapErrTrace;
use libimagerror::exit::ExitUnwrap;
use libimagerror::io::ToExitCode;
+use libimagstore::storeid::StoreId;
/// No special CLI
@@ -57,6 +60,29 @@ pub fn build_ui<'a>(app: App<'a, 'a>) -> App<'a, 'a> {
.required(false)
.multiple(false)
.help("Print the storepath for each id"))
+
+ .arg(Arg::with_name("in-collection-filter")
+ .long("in-collection")
+ .short("c")
+ .required(false)
+ .takes_value(true)
+ .multiple(true)
+ .value_names(&["COLLECTION"])
+ .help("Filter for ids which are only in these collections"))
+}
+
+pub struct IsInCollectionsFilter<'a, A>(Option<A>, ::std::marker::PhantomData<&'a str>)
+ where A: AsRef<[&'a str]>;
+
+impl<'a, A> Filter<StoreId> for IsInCollectionsFilter<'a, A>
+ where A: AsRef<[&'a str]> + 'a
+{
+ fn filter(&self, sid: &StoreId) -> bool {
+ match self.0 {
+ Some(ref colls) => sid.is_in_collection(colls),
+ None => true,
+ }
+ }
}
fn main() {
@@ -68,9 +94,17 @@ fn main() {
let print_storepath = rt.cli().is_present("print-storepath");
+ let values = rt
+ .cli()
+ .values_of("in-collection-filter")
+ .map(|v| v.collect::<Vec<&str>>());
+
+ let collection_filter = IsInCollectionsFilter(values, ::std::marker::PhantomData);
+
rt.store()
.entries()
.map_err_trace_exit_unwrap(1)
+ .filter(|id| collection_filter.filter(id))
.map(|id| if print_storepath {
id
} else {
diff --git a/bin/domain/imag-diary/src/list.rs b/bin/domain/imag-diary/src/list.rs
index 158ef57..f1a8164 100644
--- a/bin/domain/imag-diary/src/list.rs
+++ b/bin/domain/imag-diary/src/list.rs
@@ -26,6 +26,10 @@ use libimagerror::trace::MapErrTrace;
use libimagerror::io::ToExitCode;
use libimagerror::exit::ExitUnwrap;
use libimagutil::debug_result::*;
+use libimagdiary::diaryid::DiaryId;
+use libimagdiary::diaryid::FromStoreId;
+use libimagdiary::error::Result;
+
use util::get_diary_name;
@@ -33,17 +37,21 @@ 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));
- Diary::entries(rt.store(), &diaryname)
+ let mut ids = Diary::entries(rt.store(), &diaryname)
.map_dbg_str("Ok")
.map_err_trace_exit_unwrap(1)
- .for_each(|id| {
- writeln!(rt.stdout(), "{}", id
- .without_base()
- .to_str()
- .map_err_trace()
- .unwrap_or(String::from("<<Path Parsing Error>>")))
- .to_exit_code()
- .unwrap_or_exit();
- })
+ .map(|id| DiaryId::from_storeid(&id))
+ .collect::<Result<Vec<_>>>()
+ .map_err_trace_exit_unwrap(1);
+
+ ids.sort_by_key(|id| {
+ [id.year() as u32, id.month(), id.day(), id.hour(), id.minute(), id.second()]
+ });
+
+ for id in ids {
+ writeln!(rt.stdout(), "{}", id)
+ .to_exit_code()
+ .unwrap_or_exit();
+ }
}
diff --git a/lib/domain/libimagdiary/src/viewer.rs b/lib/domain/libimagdiary/src/viewer.rs
index 7d80436..17971f5 100644
--- a/lib/domain/libimagdiary/src/viewer.rs
+++ b/lib/domain/libimagdiary/src/viewer.rs
@@ -27,7 +27,6 @@ use error::Result;
use libimagstore::store::FileLockEntry;
use libimagentryview::viewer::Viewer;
use libimagentryview::builtin::plain::PlainViewer;
-use libimagerror::trace::trace_error;
/// This viewer does _not_ implement libimagentryview::viewer::Viewer because we need to be able to
/// call some diary-type specific functions on the entries passed to this.
@@ -49,11 +48,16 @@ impl DiaryViewer {
/// View all entries from the iterator, or stop immediately if an error occurs, returning that
/// error.
pub fn view_entries<'a, I: Iterator<Item = FileLockEntry<'a>>>(&self, entries: I) -> Result<()> {
- for entry in entries {
- match entry.diary_id() {
- Ok(id) => println!("{} :\n", id),
- Err(e) => trace_error(&e),
- }
+ let mut entries = entries
+ .map(|e| e.diary_id().map(|id| (id, e)))
+ .collect::<Result<Vec<_>>>()?;
+
+ entries.sort_by_key(|&(ref id, _)| {
+ [id.year() as u32, id.month(), id.day(), id.hour(), id.minute(), id.second()]
+ });
+
+ for (id, entry) in entries.into_iter() {
+ println!("{} :\n", id);
let _ = self.0
.view_entry(&entry)
.chain_err(|| DEK::ViewError)
diff --git a/lib/entry/libimagentrylink/src/internal.rs b/lib/entry/libimagentrylink/src/internal.rs
index 1048225..f3eece0 100644
--- a/lib/entry/libimagentrylink/src/internal.rs
+++ b/lib/entry/libimagentrylink/src/internal.rs
@@ -700,7 +700,6 @@ pub mod store_check {
};
// Helper function to create a SLCECD::OneDirectionalLink error object
- #[inline]
let mk_one_directional_link_err = |src: StoreId, target: StoreId| -> LE {
LE::from_kind(LEK::DeadLink(src, target))
};
diff --git a/lib/entry/libimagentryref/src/refstore.rs b/lib/entry/libimagentryref/src/refstore.rs
index f8ca94d..6f57553 100644
--- a/lib/entry/libimagentryref/src/refstore.rs
+++ b/lib/entry/libimagentryref/src/refstore.rs
@@ -103,7 +103,7 @@ impl<'a> RefStore<'a> for Store {
fn create_ref<RPG: UniqueRefPathGenerator, A: AsRef<Path>>(&'a self, path: A)
-> Result<FileLockEntry<'a>, RPG::Error>
{
- let hash = RPG::unique_hash(path)?;
+ let hash = RPG::unique_hash(&path)?;
let pathbuf = PathBuf::from(format!("{}/{}", RPG::collection(), hash));
let sid = StoreId::new_baseless(pathbuf.clone()).map_err(RE::from)?;
@@ -111,7 +111,7 @@ impl<'a> RefStore<'a> for Store {
self.create(sid)
.map_err(RE::from)
.and_then(|mut fle| {
- fle.make_ref(hash, pathbuf)?;
+ fle.make_ref(hash, path)?;
Ok(fle)
})
.map_err(RPG::Error::from)