From e1ffa4b1075c0ddc85ba4dc3b82ce50a4b2769ab Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 15 Apr 2018 10:12:17 +0200 Subject: [PATCH] Add name filtering in show command --- bin/domain/imag-wiki/src/main.rs | 18 ++++++++++++++++++ bin/domain/imag-wiki/src/ui.rs | 4 ++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/bin/domain/imag-wiki/src/main.rs b/bin/domain/imag-wiki/src/main.rs index 61f7a29b..a9b5d30e 100644 --- a/bin/domain/imag-wiki/src/main.rs +++ b/bin/domain/imag-wiki/src/main.rs @@ -197,11 +197,29 @@ fn create_in_wiki(rt: &Runtime, } fn show(rt: &Runtime, wiki_name: &str) { + use filters::filter::Filter; + let scmd = rt.cli().subcommand_matches("show").unwrap(); // safed by clap + + struct NameFilter(Option>); + impl Filter for NameFilter { + fn filter(&self, e: &String) -> bool { + match self.0 { + Some(ref v) => v.contains(e), + None => false, + } + } + } + + let namefilter = NameFilter(scmd + .values_of("show-name") + .map(|v| v.map(String::from).collect::>())); + let names = scmd .values_of("show-name") .unwrap() // safe by clap .map(String::from) + .filter(|e| namefilter.filter(e)) .collect::>(); let wiki = rt diff --git a/bin/domain/imag-wiki/src/ui.rs b/bin/domain/imag-wiki/src/ui.rs index 620fc979..171f427b 100644 --- a/bin/domain/imag-wiki/src/ui.rs +++ b/bin/domain/imag-wiki/src/ui.rs @@ -147,12 +147,12 @@ pub fn build_ui<'a>(app: App<'a, 'a>) -> App<'a, 'a> { .about("Show wiki entry/entries") .version("0.1") - .arg(Arg::with_name("create-name") + .arg(Arg::with_name("show-name") .index(1) .takes_value(true) .required(true) .multiple(true) - .help("Name of the entry/entries to show.")) + .help("Name of the entry/entries to show (if not passed, all are shown).")) )