Add name filtering in show command

This commit is contained in:
Matthias Beyer 2018-04-15 10:12:17 +02:00
parent 4450f22c5e
commit e1ffa4b107
2 changed files with 20 additions and 2 deletions

View file

@ -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<Vec<String>>);
impl Filter<String> 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::<Vec<String>>()));
let names = scmd
.values_of("show-name")
.unwrap() // safe by clap
.map(String::from)
.filter(|e| namefilter.filter(e))
.collect::<Vec<_>>();
let wiki = rt

View file

@ -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)."))
)