aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel <kingdread@gmx.de>2018-09-07 02:06:52 +0200
committerDaniel <kingdread@gmx.de>2018-09-07 02:06:52 +0200
commit8d58f0ade28e07c0d5d885478ba211fce7c05305 (patch)
tree664e3ee2ab880092876e884755b5ba03373e046f
parente8cb7b30474cb873c036ab5b7d7cb075f38a5018 (diff)
downloadraidgrep-8d58f0ade28e07c0d5d885478ba211fce7c05305.tar.gz
raidgrep-8d58f0ade28e07c0d5d885478ba211fce7c05305.tar.bz2
raidgrep-8d58f0ade28e07c0d5d885478ba211fce7c05305.zip
add filtering by outcome
-rw-r--r--src/main.rs32
1 files changed, 29 insertions, 3 deletions
diff --git a/src/main.rs b/src/main.rs
index 3246864..31e29ad 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -42,10 +42,13 @@ struct Opt {
path: PathBuf,
/// The fields which should be searched.
- /// Possible values: all, account, character
#[structopt(short = "f", long = "fields", default_value = "all")]
field: SearchField,
+ /// Only display fights with the given outcome.
+ #[structopt(short = "o", long = "outcome")]
+ outcome: Option<FightOutcome>,
+
/// The regular expression to search for.
#[structopt(name = "EXPR")]
expression: Regex,
@@ -124,6 +127,18 @@ pub enum FightOutcome {
Wipe,
}
+impl FromStr for FightOutcome {
+ type Err = &'static str;
+
+ fn from_str(s: &str) -> Result<Self, Self::Err> {
+ match s {
+ "success" => Ok(FightOutcome::Success),
+ "wipe" | "fail" => Ok(FightOutcome::Wipe),
+ _ => Err("Must be success or wipe"),
+ }
+ }
+}
+
fn main() {
let opt = Opt::from_args();
let result = grep(&opt);
@@ -183,6 +198,7 @@ fn search_log(entry: &DirEntry, opt: &Opt) -> Result<Option<LogResult>, RuntimeE
return Ok(None);
};
+ let mut candidate_good = false;
for player in log.players() {
match player.name() {
AgentName::Player {
@@ -193,14 +209,24 @@ fn search_log(entry: &DirEntry, opt: &Opt) -> Result<Option<LogResult>, RuntimeE
if (opt.field.search_account() && opt.expression.is_match(account_name))
|| (opt.field.search_character() && opt.expression.is_match(character_name))
{
- return Ok(Some(extract_info(entry, &log)));
+ candidate_good = true;
}
}
_ => unreachable!(),
}
}
- Ok(None)
+ if !candidate_good {
+ return Ok(None);
+ }
+
+ let result = extract_info(entry, &log);
+
+ match opt.outcome {
+ Some(o) if o == result.outcome => Ok(Some(result)),
+ None => Ok(Some(result)),
+ _ => Ok(None),
+ }
}
/// Extract human-readable information from the given log file.