diff options
Diffstat (limited to 'bin/core/imag-ids')
-rw-r--r-- | bin/core/imag-ids/Cargo.toml | 6 | ||||
-rw-r--r-- | bin/core/imag-ids/src/main.rs | 36 | ||||
-rw-r--r-- | bin/core/imag-ids/src/ui.rs | 40 |
3 files changed, 70 insertions, 12 deletions
diff --git a/bin/core/imag-ids/Cargo.toml b/bin/core/imag-ids/Cargo.toml index 591c190f..68ea7cb4 100644 --- a/bin/core/imag-ids/Cargo.toml +++ b/bin/core/imag-ids/Cargo.toml @@ -22,12 +22,14 @@ 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" } [dependencies.clap] -version = ">=2.29" +version = "^2.29" default-features = false -features = ["color", "suggestions"] +features = ["color", "suggestions", "wrap_help"] diff --git a/bin/core/imag-ids/src/main.rs b/bin/core/imag-ids/src/main.rs index 30e0c49f..08beb465 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,23 +41,30 @@ extern crate libimagstore; use std::io::Write; -use clap::{Arg, App}; +use filters::filter::Filter; use libimagrt::setup::generate_runtime_setup; use libimagerror::trace::MapErrTrace; use libimagerror::exit::ExitUnwrap; use libimagerror::io::ToExitCode; +use libimagstore::storeid::StoreId; +mod ui; +use ui::build_ui; -/// No special CLI -pub fn build_ui<'a>(app: App<'a, 'a>) -> App<'a, 'a> { - app - .arg(Arg::with_name("print-storepath") - .long("with-storepath") - .takes_value(false) - .required(false) - .multiple(false) - .help("Print the storepath for each id")) + +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 +76,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/core/imag-ids/src/ui.rs b/bin/core/imag-ids/src/ui.rs new file mode 100644 index 00000000..000539dd --- /dev/null +++ b/bin/core/imag-ids/src/ui.rs @@ -0,0 +1,40 @@ +// +// 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 clap::{Arg, App}; + +pub fn build_ui<'a>(app: App<'a, 'a>) -> App<'a, 'a> { + app + .arg(Arg::with_name("print-storepath") + .long("with-storepath") + .takes_value(false) + .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")) +} + |