summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2018-04-13 13:53:26 +0200
committerGitHub <noreply@github.com>2018-04-13 13:53:26 +0200
commit7d96ee5e9b14afa6b4fa117dfaabb787b7ec5650 (patch)
treeb9c6377fd75bc961aa050f7bbdc9b59d1736cbc6
parentc27dc79afe2ed2d978515dbcb737b0927783027b (diff)
parent89cf979b130609c65c7847a7214b7530fe6d77a0 (diff)
downloadimag-7d96ee5e9b14afa6b4fa117dfaabb787b7ec5650.zip
imag-7d96ee5e9b14afa6b4fa117dfaabb787b7ec5650.tar.gz
Merge pull request #1386 from matthiasbeyer/imag-ids/filter-for-collection
imag-ids: Add functionality to filter for a collection
-rw-r--r--bin/core/imag-ids/Cargo.toml2
-rw-r--r--bin/core/imag-ids/src/main.rs34
2 files changed, 36 insertions, 0 deletions
diff --git a/bin/core/imag-ids/Cargo.toml b/bin/core/imag-ids/Cargo.toml
index 0017777..891933f 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 {