diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2018-04-29 14:37:50 +0200 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2018-05-02 20:42:56 +0200 |
commit | f4e1c0864c4fd0f8da1d013f146a56d3ac677dc4 (patch) | |
tree | 4504825556c6b5d6a659d563dd31fd39faa5f75d /bin | |
parent | d51832240128d5c3c21f94e3049de84bfa758224 (diff) |
Implement 'where' subcommand
Diffstat (limited to 'bin')
-rw-r--r-- | bin/core/imag-ids/src/main.rs | 23 | ||||
-rw-r--r-- | bin/core/imag-ids/src/ui.rs | 12 |
2 files changed, 34 insertions, 1 deletions
diff --git a/bin/core/imag-ids/src/main.rs b/bin/core/imag-ids/src/main.rs index 2af2b4d3..4ce91578 100644 --- a/bin/core/imag-ids/src/main.rs +++ b/bin/core/imag-ids/src/main.rs @@ -40,6 +40,7 @@ extern crate libimagstore; #[macro_use] extern crate libimagrt; use std::io::Write; +use std::process::exit; use filters::filter::Filter; @@ -70,12 +71,34 @@ fn main() { .map(|v| v.collect::<Vec<&str>>()); let collection_filter = IsInCollectionsFilter::new(values); + let query_filter : Option<id_filters::header_filter_lang::Query> = rt + .cli() + .subcommand_matches("where") + .map(|matches| { + let query = matches.value_of("where-filter").unwrap(); // safe by clap + id_filters::header_filter_lang::parse(&query) + }); rt.store() .entries() .map_err_trace_exit_unwrap(1) .trace_unwrap_exit(1) .filter(|id| collection_filter.filter(id)) + .filter(|id| match query_filter.as_ref() { + None => true, + Some(qf) => { + let entry = rt + .store() + .get(id.clone()) + .map_err_trace_exit_unwrap(1) + .unwrap_or_else(|| { + error!("Tried to get '{}', but it does not exist!", id); + exit(1) + }); + + qf.filter(&entry) + } + }) .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 index 000539dd..c4080c8d 100644 --- a/bin/core/imag-ids/src/ui.rs +++ b/bin/core/imag-ids/src/ui.rs @@ -17,7 +17,7 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // -use clap::{Arg, App}; +use clap::{Arg, App, SubCommand}; pub fn build_ui<'a>(app: App<'a, 'a>) -> App<'a, 'a> { app @@ -36,5 +36,15 @@ pub fn build_ui<'a>(app: App<'a, 'a>) -> App<'a, 'a> { .multiple(true) .value_names(&["COLLECTION"]) .help("Filter for ids which are only in these collections")) + + .subcommand(SubCommand::with_name("where") + .arg(Arg::with_name("where-filter") + .index(1) + .required(true) + .takes_value(true) + .multiple(false) + .value_names(&["QUERY"]) + .help("Query the header of the entries and filter them")) + ) } |