From fb2a6088dcc7b57a2c1ac93ec6a8fbcc52584734 Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 13 May 2020 13:49:43 +0200 Subject: first attempt at sorting output This does currently not work yet, as we cannot call .finish() on dyn Aggregator. This needs to be adjusted. However, this provides the basic infrastructure for producing sorted output, including the required command line parsing. --- src/main.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index ee1c232..ad996ea 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,10 @@ pub struct Opt { #[structopt(long = "no-color")] no_color: bool, + /// Sort the output. + #[structopt(short = "s", long = "sort")] + sorting: Option, + /// Print more debugging information to stderr. #[structopt(long = "debug")] debug: bool, @@ -150,7 +155,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,7 +382,8 @@ fn build_filter(expr_string: &str) -> Result> { /// Run the grep search with the given options. fn grep(opt: &Opt, filter: &dyn LogFilter) -> Result<()> { - let pipeline = &output::build_pipeline(opt); + let pipeline = output::build_pipeline(opt); + let pipeline_ref = &pipeline; rayon::scope(|s| { let walker = WalkDir::new(&opt.path); for entry in walker { @@ -391,7 +397,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 +406,9 @@ fn grep(opt: &Opt, filter: &dyn LogFilter) -> Result<()> { }); } Ok(()) - }) + }) as Result<()>; + pipeline.finish(); + Ok(()) } /// Search the given single log. -- cgit v1.2.3 From b6a13c465983993ac581051bb24a13d4296731a1 Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 13 May 2020 16:33:27 +0200 Subject: fix Aggregator::finish for trait objects --- src/main.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index ad996ea..cb914d3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -384,7 +384,7 @@ fn build_filter(expr_string: &str) -> Result> { fn grep(opt: &Opt, filter: &dyn LogFilter) -> Result<()> { let pipeline = output::build_pipeline(opt); let pipeline_ref = &pipeline; - rayon::scope(|s| { + let result: Result<()> = rayon::scope(|s| { let walker = WalkDir::new(&opt.path); for entry in walker { let entry = entry?; @@ -406,7 +406,8 @@ fn grep(opt: &Opt, filter: &dyn LogFilter) -> Result<()> { }); } Ok(()) - }) as Result<()>; + }); + result?; pipeline.finish(); Ok(()) } -- cgit v1.2.3 From 61889e2d289a6d0d83d55afc9b1c98e6dd112249 Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 14 May 2020 15:55:41 +0200 Subject: add a small test for sorting with Sorting --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index cb914d3..43a6f59 100644 --- a/src/main.rs +++ b/src/main.rs @@ -107,7 +107,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, -- cgit v1.2.3 From e2d23d4b76000263e9f939637353bbc4bb9289fd Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 14 May 2020 16:08:51 +0200 Subject: add documentation about --sort --- src/main.rs | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 43a6f59..84d1063 100644 --- a/src/main.rs +++ b/src/main.rs @@ -81,6 +81,9 @@ pub struct Opt { 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, -- cgit v1.2.3