aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authorDaniel <kingdread@gmx.de>2020-05-14 16:13:28 +0200
committerDaniel <kingdread@gmx.de>2020-05-14 16:13:28 +0200
commitc973f2ddb47721254f6f5a81e4c45f0c72d793fd (patch)
tree4aa7c00b87eec09ee1faca957be508efe3dbbb65 /src/main.rs
parent331d6b1762d1d9431b210fc98a495d56ad7a1cd1 (diff)
parente2d23d4b76000263e9f939637353bbc4bb9289fd (diff)
downloadraidgrep-c973f2ddb47721254f6f5a81e4c45f0c72d793fd.tar.gz
raidgrep-c973f2ddb47721254f6f5a81e4c45f0c72d793fd.tar.bz2
raidgrep-c973f2ddb47721254f6f5a81e4c45f0c72d793fd.zip
Merge branch 'sorted-output'
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs24
1 files changed, 18 insertions, 6 deletions
diff --git a/src/main.rs b/src/main.rs
index ee1c232..84d1063 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -25,6 +25,7 @@ use filters::{log::LogFilter, Inclusion};
mod guilds;
mod logger;
mod output;
+use output::sorting::Sorting;
mod paths;
mod playerclass;
use playerclass::PlayerClass;
@@ -79,6 +80,13 @@ pub struct Opt {
#[structopt(long = "no-color")]
no_color: bool,
+ /// Sort the output.
+ ///
+ /// Valid sorting fields are date, boss, cm and outcome. Prefix the field with ~ to sort in
+ /// descending order.
+ #[structopt(short = "s", long = "sort")]
+ sorting: Option<Sorting>,
+
/// Print more debugging information to stderr.
#[structopt(long = "debug")]
debug: bool,
@@ -102,7 +110,7 @@ pub struct Opt {
}
/// A log that matches the search criteria.
-#[derive(Debug, Clone)]
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct LogResult {
/// The path to the log file.
log_file: PathBuf,
@@ -150,7 +158,7 @@ impl Ord for Player {
}
/// Outcome of the fight.
-#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
+#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub enum FightOutcome {
Success,
Wipe,
@@ -377,8 +385,9 @@ fn build_filter(expr_string: &str) -> Result<Box<dyn LogFilter>> {
/// Run the grep search with the given options.
fn grep(opt: &Opt, filter: &dyn LogFilter) -> Result<()> {
- let pipeline = &output::build_pipeline(opt);
- rayon::scope(|s| {
+ let pipeline = output::build_pipeline(opt);
+ let pipeline_ref = &pipeline;
+ let result: Result<()> = rayon::scope(|s| {
let walker = WalkDir::new(&opt.path);
for entry in walker {
let entry = entry?;
@@ -391,7 +400,7 @@ fn grep(opt: &Opt, filter: &dyn LogFilter) -> Result<()> {
let search = search_log(&entry, filter);
match search {
Ok(None) => (),
- Ok(Some(result)) => pipeline.push_item(&result),
+ Ok(Some(result)) => pipeline_ref.push_item(result),
Err(err) => {
debug!("Runtime error while scanning {:?}: {}", entry.path(), err);
}
@@ -400,7 +409,10 @@ fn grep(opt: &Opt, filter: &dyn LogFilter) -> Result<()> {
});
}
Ok(())
- })
+ });
+ result?;
+ pipeline.finish();
+ Ok(())
}
/// Search the given single log.