aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authorDaniel <kingdread@gmx.de>2018-09-07 01:40:39 +0200
committerDaniel <kingdread@gmx.de>2018-09-07 01:40:39 +0200
commit198a2d11fdeb0d1bac0f75db7535776a6709e124 (patch)
treeb9eb7727166b879ff35fd2ad4064a5b9e59dbc1c /src/main.rs
parentaf3ab806a94f3654f411925e6917a9ea1250856b (diff)
downloadraidgrep-198a2d11fdeb0d1bac0f75db7535776a6709e124.tar.gz
raidgrep-198a2d11fdeb0d1bac0f75db7535776a6709e124.tar.bz2
raidgrep-198a2d11fdeb0d1bac0f75db7535776a6709e124.zip
more comments & formatting
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs33
1 files changed, 31 insertions, 2 deletions
diff --git a/src/main.rs b/src/main.rs
index c70a62a..b366a17 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -4,9 +4,9 @@ extern crate quick_error;
extern crate chrono;
extern crate colored;
extern crate evtclib;
+extern crate rayon;
extern crate regex;
extern crate walkdir;
-extern crate rayon;
use std::fs::File;
use std::io::{self, BufReader};
@@ -27,6 +27,8 @@ use errors::RuntimeError;
mod output;
+/// A program that allows you to search through all your evtc logs for specific
+/// people.
#[derive(StructOpt, Debug)]
#[structopt(name = "raidgrep")]
struct Opt {
@@ -44,15 +46,19 @@ struct Opt {
#[structopt(short = "f", long = "fields", default_value = "all")]
field: SearchField,
- /// The expression to search for.
+ /// The regular expression to search for.
#[structopt(name = "EXPR")]
expression: Regex,
}
+/// A flag indicating which fields should be searched.
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
enum SearchField {
+ /// Search all fields.
All,
+ /// Only search the account name.
Account,
+ /// Only search the character name.
Character,
}
@@ -69,23 +75,35 @@ impl FromStr for SearchField {
}
}
+/// A log that matches the search criteria.
#[derive(Debug, Clone)]
pub struct LogResult {
+ /// The path to the log file.
log_file: PathBuf,
+ /// The time of the recording.
time: NaiveDateTime,
+ /// The name of the boss.
boss_name: String,
+ /// A vector of all participating players.
players: Vec<Player>,
+ /// The outcome of the fight.
outcome: FightOutcome,
}
+/// A player.
#[derive(Debug, Clone)]
pub struct Player {
+ /// Account name of the player.
account_name: String,
+ /// Character name of the player.
character_name: String,
+ /// Profession (or elite specialization) as english name.
profession: String,
+ /// Subsquad that the player was in.
subgroup: u8,
}
+/// Outcome of the fight.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum FightOutcome {
Success,
@@ -103,6 +121,7 @@ fn main() {
}
}
+/// Check if the given entry represents a log file, based on the file name.
fn is_log_file(entry: &DirEntry) -> bool {
entry
.file_name()
@@ -111,6 +130,7 @@ fn is_log_file(entry: &DirEntry) -> bool {
.unwrap_or(false)
}
+/// Run the grep search with the given options.
fn grep(opt: &Opt) -> Result<(), RuntimeError> {
let walker = WalkDir::new(&opt.path);
let entries = walker.into_iter().collect::<Vec<_>>();
@@ -125,6 +145,11 @@ fn grep(opt: &Opt) -> Result<(), RuntimeError> {
})
}
+/// Search the given single log.
+///
+/// If the log matches, returns `Ok(Some(..))`.
+/// If the log doesn't match, returns `Ok(None)`.
+/// If there was a fatal error, returns `Err(..)`.
fn search_log(entry: &DirEntry, opt: &Opt) -> Result<Option<LogResult>, RuntimeError> {
let mut input = BufReader::new(File::open(entry.path())?);
let raw = if entry
@@ -166,6 +191,7 @@ fn search_log(entry: &DirEntry, opt: &Opt) -> Result<Option<LogResult>, RuntimeE
Ok(None)
}
+/// Extract human-readable information from the given log file.
fn extract_info(entry: &DirEntry, log: &Log) -> LogResult {
let boss_name = match log.boss().name() {
AgentName::Single(s) => s,
@@ -206,6 +232,7 @@ fn extract_info(entry: &DirEntry, log: &Log) -> LogResult {
}
}
+/// Get the timestamp of the log start time.
fn get_start_timestamp(log: &Log) -> u32 {
for event in log.events() {
if let EventKind::LogStart {
@@ -218,6 +245,7 @@ fn get_start_timestamp(log: &Log) -> u32 {
0
}
+/// Get the outcome of the fight.
fn get_fight_outcome(log: &Log) -> FightOutcome {
for event in log.events() {
if let EventKind::Reward { .. } = event.kind {
@@ -227,6 +255,7 @@ fn get_fight_outcome(log: &Log) -> FightOutcome {
FightOutcome::Wipe
}
+/// Get the (english) name for the given profession/elite specialization.
fn get_profession_name(profession: u32, elite: u32) -> &'static str {
match (profession, elite) {
(1, 0) => "Guardian",