Add name filtering in show command
This commit is contained in:
parent
4450f22c5e
commit
e1ffa4b107
2 changed files with 20 additions and 2 deletions
|
@ -197,11 +197,29 @@ fn create_in_wiki(rt: &Runtime,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn show(rt: &Runtime, wiki_name: &str) {
|
fn show(rt: &Runtime, wiki_name: &str) {
|
||||||
|
use filters::filter::Filter;
|
||||||
|
|
||||||
let scmd = rt.cli().subcommand_matches("show").unwrap(); // safed by clap
|
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
|
let names = scmd
|
||||||
.values_of("show-name")
|
.values_of("show-name")
|
||||||
.unwrap() // safe by clap
|
.unwrap() // safe by clap
|
||||||
.map(String::from)
|
.map(String::from)
|
||||||
|
.filter(|e| namefilter.filter(e))
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
let wiki = rt
|
let wiki = rt
|
||||||
|
|
|
@ -147,12 +147,12 @@ pub fn build_ui<'a>(app: App<'a, 'a>) -> App<'a, 'a> {
|
||||||
.about("Show wiki entry/entries")
|
.about("Show wiki entry/entries")
|
||||||
.version("0.1")
|
.version("0.1")
|
||||||
|
|
||||||
.arg(Arg::with_name("create-name")
|
.arg(Arg::with_name("show-name")
|
||||||
.index(1)
|
.index(1)
|
||||||
.takes_value(true)
|
.takes_value(true)
|
||||||
.required(true)
|
.required(true)
|
||||||
.multiple(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)."))
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue