Remove grep functionality

This commit is contained in:
Matthias Beyer 2018-04-14 20:28:08 +02:00
parent caf0e63b35
commit cc9e7c89d0
2 changed files with 0 additions and 60 deletions

View file

@ -63,7 +63,6 @@ fn main() {
Some("create") => create(&rt, wiki_name), Some("create") => create(&rt, wiki_name),
Some("create-wiki") => create_wiki(&rt, wiki_name), Some("create-wiki") => create_wiki(&rt, wiki_name),
Some("delete") => delete(&rt, wiki_name), Some("delete") => delete(&rt, wiki_name),
Some("grep") => grep(&rt, wiki_name),
Some(other) => { Some(other) => {
debug!("Unknown command"); debug!("Unknown command");
let _ = rt.handle_unknown_subcommand("imag-wiki", other, rt.cli()) let _ = rt.handle_unknown_subcommand("imag-wiki", other, rt.cli())
@ -228,49 +227,3 @@ fn delete(rt: &Runtime, wiki_name: &str) {
.map_err_trace_exit_unwrap(1); .map_err_trace_exit_unwrap(1);
} }
fn grep(rt: &Runtime, wiki_name: &str) {
use libimagstore::iter::get::StoreIdGetIteratorExtension;
use filters::filter::Filter;
let scmd = rt.cli().subcommand_matches("grep").unwrap(); // safed by clap
let grep = scmd
.value_of("grep-pattern")
.map(Regex::new)
.unwrap() // safed by clap
.unwrap_or_else(|e| {
error!("Regex building error: {:?}", e);
::std::process::exit(1)
});
let filter = |e: &FileLockEntry| -> bool {
grep.is_match(e.get_content())
};
let wiki = rt
.store()
.get_wiki(&wiki_name)
.map_err_trace_exit_unwrap(1)
.unwrap_or_else(|| {
error!("No wiki '{}' found", wiki_name);
::std::process::exit(1)
});
let out = rt.stdout();
let mut outlock = out.lock();
wiki.all_ids()
.map_err_trace_exit_unwrap(1)
.into_get_iter(rt.store())
.filter_map(Result::ok)
.map(|e| e.unwrap_or_else(|| {
error!("Failed to fetch entry");
::std::process::exit(1)
}))
.filter(|e| filter.filter(e))
.for_each(|entry| {
let _ = writeln!(outlock, "{}", entry.get_location())
.to_exit_code()
.unwrap_or_exit();
});
}

View file

@ -162,17 +162,4 @@ pub fn build_ui<'a>(app: App<'a, 'a>) -> App<'a, 'a> {
.help("Do not remote links. WARNING: This leaves the store in an inconsistent state.")) .help("Do not remote links. WARNING: This leaves the store in an inconsistent state."))
) )
.subcommand(SubCommand::with_name("grep")
.about("Grep though wiki entries.")
.version("0.1")
.arg(Arg::with_name("grep-pattern")
.index(1)
.takes_value(true)
.required(false)
.multiple(true)
.value_name("PATTERN")
.value_names(&["PATTERNS"])
.help("List only entries where the content matches the pattern. Regex allowed."))
)
} }