diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/main.rs | 33 | ||||
| -rw-r--r-- | src/output.rs | 2 | 
2 files changed, 32 insertions, 3 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", diff --git a/src/output.rs b/src/output.rs index 9458e48..3a06973 100644 --- a/src/output.rs +++ b/src/output.rs @@ -1,5 +1,5 @@ -use super::{LogResult, FightOutcome};  use super::errors::RuntimeError; +use super::{FightOutcome, LogResult};  use std::io::Write; | 
