From 2c1203f6f2c3e6bbaf527fa202425ed465e89d69 Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 10 Sep 2018 00:40:29 +0200 Subject: move filtering into own submodule --- src/main.rs | 36 +++++++++--------------------------- 1 file changed, 9 insertions(+), 27 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 9343e14..2e3007c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -27,11 +27,13 @@ use errors::RuntimeError; mod output; +mod filters; + /// A program that allows you to search through all your evtc logs for specific /// people. #[derive(StructOpt, Debug)] #[structopt(name = "raidgrep")] -struct Opt { +pub struct Opt { /// Path to the folder with logs. #[structopt( short = "d", @@ -207,34 +209,14 @@ fn search_log(entry: &DirEntry, opt: &Opt) -> Result, RuntimeE return Ok(None); }; - let mut candidate_good = false; - for player in log.players() { - match player.name() { - AgentName::Player { - account_name, - character_name, - .. - } => { - if (opt.field.search_account() && opt.expression.is_match(account_name)) - || (opt.field.search_character() && opt.expression.is_match(character_name)) - { - candidate_good = true; - } - } - _ => unreachable!(), - } - } - - if !candidate_good { - return Ok(None); - } + let info = extract_info(entry, &log); - let result = extract_info(entry, &log); + let take_log = filters::filter_name(&log, opt) && filters::filter_outcome(&info, opt); - match opt.outcome { - Some(o) if o == result.outcome => Ok(Some(result)), - None => Ok(Some(result)), - _ => Ok(None), + if take_log { + Ok(Some(info)) + } else { + Ok(None) } } -- cgit v1.2.3