From 4e045cb186cda395b22dc1cdba7dc9906c64bdee Mon Sep 17 00:00:00 2001 From: Kevin Matthes <92332892+kevinmatthes@users.noreply.github.com> Date: Thu, 19 May 2022 17:57:39 +0200 Subject: [PATCH 01/31] Fix typo: `analzer` instead of `analyzer` --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 72b9565..3a36474 100644 --- a/src/main.rs +++ b/src/main.rs @@ -79,7 +79,7 @@ fn main() -> Result<(), Box> { let matches = match opts.parse(std::env::args()) { Ok(it) => it, Err(err) => { - usage("commit-analzer", opts); + usage("commit-analyzer", opts); return Err(err.into()); } }; From 1c1208473c3847f1932f477f824abf84dabd418f Mon Sep 17 00:00:00 2001 From: Kevin Matthes <92332892+kevinmatthes@users.noreply.github.com> Date: Thu, 19 May 2022 18:06:28 +0200 Subject: [PATCH 02/31] Create usage.rs --- src/usage.rs | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 src/usage.rs diff --git a/src/usage.rs b/src/usage.rs new file mode 100644 index 0000000..9be6eb5 --- /dev/null +++ b/src/usage.rs @@ -0,0 +1,5 @@ +pub fn usage (app_name: & str, opts: & getopts :: Options) +{ + println ! ("Usage: {} [OPTIONS]", app_name); + println ! ("{}", options.usage ("Parses the output of `git log`.")); +} From eed16079332145ac48916b470e9dc1319f063f69 Mon Sep 17 00:00:00 2001 From: Kevin Matthes <92332892+kevinmatthes@users.noreply.github.com> Date: Thu, 19 May 2022 18:09:23 +0200 Subject: [PATCH 03/31] Load function from module --- src/main.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index 3a36474..ca2de91 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,8 @@ +use crate :: usage :: usage; use std::{collections::HashMap, error::Error, io::Write, num::ParseIntError, ops::AddAssign}; +pub mod usage; + fn main() -> Result<(), Box> { let mut opts = getopts::Options::new(); let opts = opts @@ -176,11 +179,6 @@ fn main() -> Result<(), Box> { Ok(()) } -fn usage(program_name: &str, opts: &getopts::Options) { - println!("Usage: {} [OPTIONS]\n", program_name); - println!("{}", opts.usage("Parses the output of `git log`.")); -} - fn matches_filter(commit: &Commit, filter: &Filter) -> bool { filter.check_author_name(&commit.author.name) && filter.check_author_email(&commit.author.email) From f580e792cb180de12c729d538db21afd52343918 Mon Sep 17 00:00:00 2001 From: Kevin Matthes <92332892+kevinmatthes@users.noreply.github.com> Date: Thu, 19 May 2022 18:10:39 +0200 Subject: [PATCH 04/31] Fix typo: wrong parameter name --- src/usage.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/usage.rs b/src/usage.rs index 9be6eb5..aeec257 100644 --- a/src/usage.rs +++ b/src/usage.rs @@ -1,4 +1,4 @@ -pub fn usage (app_name: & str, opts: & getopts :: Options) +pub fn usage (app_name: & str, options: & getopts :: Options) { println ! ("Usage: {} [OPTIONS]", app_name); println ! ("{}", options.usage ("Parses the output of `git log`.")); From 8db2f263a2562245e19ff638870da8275b93a0b1 Mon Sep 17 00:00:00 2001 From: Kevin Matthes <92332892+kevinmatthes@users.noreply.github.com> Date: Thu, 19 May 2022 18:28:55 +0200 Subject: [PATCH 05/31] Make the functon `return` at the end explicitly --- src/usage.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/usage.rs b/src/usage.rs index aeec257..9a8f5e3 100644 --- a/src/usage.rs +++ b/src/usage.rs @@ -1,5 +1,6 @@ -pub fn usage (app_name: & str, options: & getopts :: Options) +pub fn usage (app_name: & str, options: & getopts :: Options) -> () { println ! ("Usage: {} [OPTIONS]", app_name); println ! ("{}", options.usage ("Parses the output of `git log`.")); + return; } From 0ad091bb3e04545a289013e5de577e4e6d8970e7 Mon Sep 17 00:00:00 2001 From: Kevin Matthes <92332892+kevinmatthes@users.noreply.github.com> Date: Thu, 19 May 2022 18:35:38 +0200 Subject: [PATCH 06/31] Add missing full stop --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index ca2de91..48bf64d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,7 +6,7 @@ pub mod usage; fn main() -> Result<(), Box> { let mut opts = getopts::Options::new(); let opts = opts - .optflag("q", "quiet", "Hides the output of commit messages") + .optflag("q", "quiet", "Hides the output of commit messages.") .optmulti( "a", "author-contains", From f6cf1841d7bed7dbd3b4a0805980bd976def7793 Mon Sep 17 00:00:00 2001 From: Kevin Matthes <92332892+kevinmatthes@users.noreply.github.com> Date: Thu, 19 May 2022 18:37:46 +0200 Subject: [PATCH 07/31] Add option for help --- src/main.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main.rs b/src/main.rs index 48bf64d..1f5fe3e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,6 +7,7 @@ fn main() -> Result<(), Box> { let mut opts = getopts::Options::new(); let opts = opts .optflag("q", "quiet", "Hides the output of commit messages.") + .optflag("h", "help", "Show this help and exit.") .optmulti( "a", "author-contains", @@ -86,6 +87,11 @@ fn main() -> Result<(), Box> { return Err(err.into()); } }; + if matches.opt_present ("h") + { + usage (& matches.free[0x0], opts); + return Ok (()); + }; if matches.free.len() < 2 { usage(&matches.free[0], opts); return Ok(()); From 66d03eb67d1d00de92794f055221e78bb27bf409 Mon Sep 17 00:00:00 2001 From: Kevin Matthes <92332892+kevinmatthes@users.noreply.github.com> Date: Thu, 19 May 2022 18:55:44 +0200 Subject: [PATCH 08/31] Remove obsolete visibility level --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 1f5fe3e..cfcb51f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,7 @@ use crate :: usage :: usage; use std::{collections::HashMap, error::Error, io::Write, num::ParseIntError, ops::AddAssign}; -pub mod usage; +mod usage; fn main() -> Result<(), Box> { let mut opts = getopts::Options::new(); From 962bf786b139a851adcec8f6139563084cb5f7b2 Mon Sep 17 00:00:00 2001 From: Kevin Matthes <92332892+kevinmatthes@users.noreply.github.com> Date: Thu, 19 May 2022 19:24:32 +0200 Subject: [PATCH 09/31] Load required module appropriately --- src/usage.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/usage.rs b/src/usage.rs index 9a8f5e3..93cdfb8 100644 --- a/src/usage.rs +++ b/src/usage.rs @@ -1,4 +1,6 @@ -pub fn usage (app_name: & str, options: & getopts :: Options) -> () +use getopts :: Options; + +pub fn usage (app_name: & str, options: & Options) -> () { println ! ("Usage: {} [OPTIONS]", app_name); println ! ("{}", options.usage ("Parses the output of `git log`.")); From c9ed9e791a01272709c7c6a16af0c87915b38b08 Mon Sep 17 00:00:00 2001 From: Kevin Matthes <92332892+kevinmatthes@users.noreply.github.com> Date: Thu, 19 May 2022 19:26:08 +0200 Subject: [PATCH 10/31] Hard code application name --- src/usage.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/usage.rs b/src/usage.rs index 93cdfb8..a680be9 100644 --- a/src/usage.rs +++ b/src/usage.rs @@ -2,7 +2,8 @@ use getopts :: Options; pub fn usage (app_name: & str, options: & Options) -> () { - println ! ("Usage: {} [OPTIONS]", app_name); - println ! ("{}", options.usage ("Parses the output of `git log`.")); + println ! ( "Usage: commit-analyzer [OPTIONS]\n{}" + , options.usage ("Parses the output of `git log`.") + ); return; } From 36a3e8c39e2fb33e0b2c2ecd9eec5b03538908bf Mon Sep 17 00:00:00 2001 From: Kevin Matthes <92332892+kevinmatthes@users.noreply.github.com> Date: Thu, 19 May 2022 19:27:30 +0200 Subject: [PATCH 11/31] Adjust function call due to previous commit --- src/main.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index cfcb51f..d817b96 100644 --- a/src/main.rs +++ b/src/main.rs @@ -83,17 +83,17 @@ fn main() -> Result<(), Box> { let matches = match opts.parse(std::env::args()) { Ok(it) => it, Err(err) => { - usage("commit-analyzer", opts); + usage(opts); return Err(err.into()); } }; if matches.opt_present ("h") { - usage (& matches.free[0x0], opts); + usage (opts); return Ok (()); }; if matches.free.len() < 2 { - usage(&matches.free[0], opts); + usage(opts); return Ok(()); } let is_quiet = matches.opt_present("q"); From b6cc1048454cfa95edf20c8798edb0e115e3a65d Mon Sep 17 00:00:00 2001 From: Kevin Matthes <92332892+kevinmatthes@users.noreply.github.com> Date: Thu, 19 May 2022 19:28:37 +0200 Subject: [PATCH 12/31] Remove obsolete parameter --- src/usage.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/usage.rs b/src/usage.rs index a680be9..b66d982 100644 --- a/src/usage.rs +++ b/src/usage.rs @@ -1,6 +1,6 @@ use getopts :: Options; -pub fn usage (app_name: & str, options: & Options) -> () +pub fn usage (options: & Options) -> () { println ! ( "Usage: commit-analyzer [OPTIONS]\n{}" , options.usage ("Parses the output of `git log`.") From 706341671ece729ddd8338aa931793f374ab8f3d Mon Sep 17 00:00:00 2001 From: Kevin Matthes <92332892+kevinmatthes@users.noreply.github.com> Date: Thu, 19 May 2022 19:30:26 +0200 Subject: [PATCH 13/31] Unite control flow branches --- src/main.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index d817b96..982a9af 100644 --- a/src/main.rs +++ b/src/main.rs @@ -87,15 +87,11 @@ fn main() -> Result<(), Box> { return Err(err.into()); } }; - if matches.opt_present ("h") + if matches.opt_present ("h") || matches.free.len < 0x2 { usage (opts); return Ok (()); }; - if matches.free.len() < 2 { - usage(opts); - return Ok(()); - } let is_quiet = matches.opt_present("q"); let max_diff_hours: u32 = match matches.opt_str("duration").map(|str| str.parse()) { None => 3, From 560097408d6a78fcce4e29d3cd1ca9ce56831223 Mon Sep 17 00:00:00 2001 From: Kevin Matthes <92332892+kevinmatthes@users.noreply.github.com> Date: Thu, 19 May 2022 19:54:10 +0200 Subject: [PATCH 14/31] Add missing space character --- src/usage.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/usage.rs b/src/usage.rs index b66d982..260d3fd 100644 --- a/src/usage.rs +++ b/src/usage.rs @@ -2,7 +2,7 @@ use getopts :: Options; pub fn usage (options: & Options) -> () { - println ! ( "Usage: commit-analyzer [OPTIONS]\n{}" + println ! ( "Usage: commit-analyzer [OPTIONS]\n{}" , options.usage ("Parses the output of `git log`.") ); return; From 383b3c2b1c92f62c8898d5ae08f163dd1cc54b5e Mon Sep 17 00:00:00 2001 From: Kevin Matthes <92332892+kevinmatthes@users.noreply.github.com> Date: Thu, 19 May 2022 19:54:52 +0200 Subject: [PATCH 15/31] Document function --- src/usage.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/usage.rs b/src/usage.rs index 260d3fd..4ebb89b 100644 --- a/src/usage.rs +++ b/src/usage.rs @@ -1,5 +1,11 @@ use getopts :: Options; +/// A small in-app documentation. +/// +/// * `options` - The options the render the tool tips for. +/// +/// This function will write a brief usage information, including a short +/// introduction to the meaning of the configured options, to `stdout`. pub fn usage (options: & Options) -> () { println ! ( "Usage: commit-analyzer [OPTIONS]\n{}" From 0e6aa27e7e545ee481742a1c9d3654ebded944a4 Mon Sep 17 00:00:00 2001 From: Kevin Matthes <92332892+kevinmatthes@users.noreply.github.com> Date: Thu, 19 May 2022 19:56:03 +0200 Subject: [PATCH 16/31] Document source file --- src/usage.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/usage.rs b/src/usage.rs index 4ebb89b..21d44a8 100644 --- a/src/usage.rs +++ b/src/usage.rs @@ -1,3 +1,12 @@ +//! The module for the usage advice. +//! +//! The usage advice defined in this module is specialised regarding the needs +//! of this application. This is, +//! +//! * the application name is hard coded, +//! * the tool tip is hard coded, and +//! * the expected order of arguments in the usage template is hard coded. + use getopts :: Options; /// A small in-app documentation. From df078425c8fc32cad195f78419808735db6e405d Mon Sep 17 00:00:00 2001 From: Kevin Matthes <92332892+kevinmatthes@users.noreply.github.com> Date: Thu, 19 May 2022 19:57:34 +0200 Subject: [PATCH 17/31] Add missing parentheses --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 982a9af..06642be 100644 --- a/src/main.rs +++ b/src/main.rs @@ -87,7 +87,7 @@ fn main() -> Result<(), Box> { return Err(err.into()); } }; - if matches.opt_present ("h") || matches.free.len < 0x2 + if matches.opt_present ("h") || matches.free.len () < 0x2 { usage (opts); return Ok (()); From 3cf8f98b595c98740acf032a2d8bf6429171296b Mon Sep 17 00:00:00 2001 From: Kevin Matthes <92332892+kevinmatthes@users.noreply.github.com> Date: Thu, 19 May 2022 20:01:11 +0200 Subject: [PATCH 18/31] Add new ignore pattern --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 5162609..3991658 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /target *.txt *.csv +*.log From a7616157d1222410463da0ed5b0de414f40ccf6c Mon Sep 17 00:00:00 2001 From: Kevin Matthes <92332892+kevinmatthes@users.noreply.github.com> Date: Thu, 19 May 2022 20:01:48 +0200 Subject: [PATCH 19/31] Sort entries by alphabet --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 3991658..f56489f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ /target -*.txt *.csv *.log +*.txt From 4b71ef4253dc5e616847531482d7dd9957126939 Mon Sep 17 00:00:00 2001 From: Kevin Matthes Date: Thu, 19 May 2022 20:36:02 +0200 Subject: [PATCH 20/31] Optimise code with `cargo fmt` --- src/main.rs | 21 ++++++++++++++------- src/usage.rs | 12 ++++++------ 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/main.rs b/src/main.rs index 06642be..2d0879b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,4 @@ -use crate :: usage :: usage; +use crate::usage::usage; use std::{collections::HashMap, error::Error, io::Write, num::ParseIntError, ops::AddAssign}; mod usage; @@ -87,10 +87,9 @@ fn main() -> Result<(), Box> { return Err(err.into()); } }; - if matches.opt_present ("h") || matches.free.len () < 0x2 - { - usage (opts); - return Ok (()); + if matches.opt_present("h") || matches.free.len() < 0x2 { + usage(opts); + return Ok(()); }; let is_quiet = matches.opt_present("q"); let max_diff_hours: u32 = match matches.opt_str("duration").map(|str| str.parse()) { @@ -239,7 +238,11 @@ impl Filter { } fn check_loc(&self, loc: &&Loc) -> bool { - self.file_extension.is_empty() || self.file_extension.iter().any(|ext| loc.file.ends_with(&format!(".{}", ext))) + self.file_extension.is_empty() + || self + .file_extension + .iter() + .any(|ext| loc.file.ends_with(&format!(".{}", ext))) } } @@ -352,7 +355,11 @@ pub struct Commit { impl Commit { pub fn loc(&self, filter: &Filter) -> i64 { - self.locs.iter().filter(|l| filter.check_loc(l)).map(|l| l.loc()).sum() + self.locs + .iter() + .filter(|l| filter.check_loc(l)) + .map(|l| l.loc()) + .sum() } } diff --git a/src/usage.rs b/src/usage.rs index 21d44a8..293a7fe 100644 --- a/src/usage.rs +++ b/src/usage.rs @@ -7,7 +7,7 @@ //! * the tool tip is hard coded, and //! * the expected order of arguments in the usage template is hard coded. -use getopts :: Options; +use getopts::Options; /// A small in-app documentation. /// @@ -15,10 +15,10 @@ use getopts :: Options; /// /// This function will write a brief usage information, including a short /// introduction to the meaning of the configured options, to `stdout`. -pub fn usage (options: & Options) -> () -{ - println ! ( "Usage: commit-analyzer [OPTIONS]\n{}" - , options.usage ("Parses the output of `git log`.") - ); +pub fn usage(options: &Options) -> () { + println!( + "Usage: commit-analyzer [OPTIONS]\n{}", + options.usage("Parses the output of `git log`.") + ); return; } From 8d3226ddc1963fe7c929752c855c5c5bbdb58c33 Mon Sep 17 00:00:00 2001 From: Kevin Matthes Date: Thu, 19 May 2022 20:37:25 +0200 Subject: [PATCH 21/31] Apply linter suggestions --- src/usage.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/usage.rs b/src/usage.rs index 293a7fe..2db161f 100644 --- a/src/usage.rs +++ b/src/usage.rs @@ -15,10 +15,9 @@ use getopts::Options; /// /// This function will write a brief usage information, including a short /// introduction to the meaning of the configured options, to `stdout`. -pub fn usage(options: &Options) -> () { +pub fn usage(options: &Options) { println!( "Usage: commit-analyzer [OPTIONS]\n{}", options.usage("Parses the output of `git log`.") ); - return; } From 84126f2d6880128f6b8aabc34d4dbe34ac30fc9f Mon Sep 17 00:00:00 2001 From: Kevin Matthes <92332892+kevinmatthes@users.noreply.github.com> Date: Fri, 20 May 2022 15:49:22 +0200 Subject: [PATCH 22/31] Add accidentally forgotten newline whitespace --- src/usage.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/usage.rs b/src/usage.rs index 2db161f..04f4ef9 100644 --- a/src/usage.rs +++ b/src/usage.rs @@ -17,7 +17,7 @@ use getopts::Options; /// introduction to the meaning of the configured options, to `stdout`. pub fn usage(options: &Options) { println!( - "Usage: commit-analyzer [OPTIONS]\n{}", + "Usage: commit-analyzer [OPTIONS]\n\n{}", options.usage("Parses the output of `git log`.") ); } From bf4adf5333858501a5c5bd195249db810fe596f6 Mon Sep 17 00:00:00 2001 From: Kevin Matthes <92332892+kevinmatthes@users.noreply.github.com> Date: Fri, 20 May 2022 15:52:12 +0200 Subject: [PATCH 23/31] Adjust function documentation --- src/usage.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/usage.rs b/src/usage.rs index 04f4ef9..9c59b95 100644 --- a/src/usage.rs +++ b/src/usage.rs @@ -11,10 +11,8 @@ use getopts::Options; /// A small in-app documentation. /// -/// * `options` - The options the render the tool tips for. -/// /// This function will write a brief usage information, including a short -/// introduction to the meaning of the configured options, to `stdout`. +/// introduction to the meaning of the configured `options`, to `stdout`. pub fn usage(options: &Options) { println!( "Usage: commit-analyzer [OPTIONS]\n\n{}", From 6899b5f46b710d96a4b03476ab15287ba31828bc Mon Sep 17 00:00:00 2001 From: Kevin Matthes <92332892+kevinmatthes@users.noreply.github.com> Date: Fri, 20 May 2022 15:55:11 +0200 Subject: [PATCH 24/31] Shorten the import of project related module --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 2d0879b..b150e8d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,5 @@ -use crate::usage::usage; use std::{collections::HashMap, error::Error, io::Write, num::ParseIntError, ops::AddAssign}; +use usage::usage; mod usage; From ee1cdfabe7810deb3ebdb3c2ff3970bd0b00ccce Mon Sep 17 00:00:00 2001 From: Kevin Matthes <92332892+kevinmatthes@users.noreply.github.com> Date: Fri, 20 May 2022 15:59:09 +0200 Subject: [PATCH 25/31] Revert hexadecimal representation --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index b150e8d..9e41488 100644 --- a/src/main.rs +++ b/src/main.rs @@ -87,7 +87,7 @@ fn main() -> Result<(), Box> { return Err(err.into()); } }; - if matches.opt_present("h") || matches.free.len() < 0x2 { + if matches.opt_present("h") || matches.free.len() < 2 { usage(opts); return Ok(()); }; From 04d23968089eba70eda503fcab894bffd71a0b57 Mon Sep 17 00:00:00 2001 From: Kevin Matthes <92332892+kevinmatthes@users.noreply.github.com> Date: Fri, 20 May 2022 16:01:07 +0200 Subject: [PATCH 26/31] Remove obsolete semicolon --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 9e41488..40b3812 100644 --- a/src/main.rs +++ b/src/main.rs @@ -90,7 +90,7 @@ fn main() -> Result<(), Box> { if matches.opt_present("h") || matches.free.len() < 2 { usage(opts); return Ok(()); - }; + } let is_quiet = matches.opt_present("q"); let max_diff_hours: u32 = match matches.opt_str("duration").map(|str| str.parse()) { None => 3, From fb72242f186c4c542631ec5ed25fa8b9fe2f8d43 Mon Sep 17 00:00:00 2001 From: Kevin Matthes Date: Fri, 20 May 2022 16:31:27 +0200 Subject: [PATCH 27/31] Fix linter warnings with `cargo clippy --fix` --- src/main.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index 40b3812..ff27639 100644 --- a/src/main.rs +++ b/src/main.rs @@ -323,7 +323,7 @@ fn parse_commit(commit: &str) -> Result<(Commit, &str), CommitParseError> { if loc.is_empty() || loc.starts_with("commit") { break; } - locs.push(Loc::parse(loc).map_err(|err| CommitParseError::LocFailed(err))?); + locs.push(Loc::parse(loc).map_err(CommitParseError::LocFailed)?); remainder_result = remainder; if let Some(remainder) = remainder_result.strip_prefix('\n') { remainder_result = remainder; @@ -334,9 +334,9 @@ fn parse_commit(commit: &str) -> Result<(Commit, &str), CommitParseError> { let commit = Commit { commit: commit.into(), merge, - author: Author::parse(author).map_err(|err| CommitParseError::AuthorFailed(err))?, + author: Author::parse(author).map_err(CommitParseError::AuthorFailed)?, date: chrono::DateTime::parse_from_str(date, "%a %b %e %T %Y %z") - .map_err(|err| CommitParseError::DateFailed(err))?, + .map_err(CommitParseError::DateFailed)?, message: message.into(), locs, }; @@ -417,7 +417,7 @@ impl Loc { Some( added .parse() - .map_err(|err| LocParseError::AddedParseError(err))?, + .map_err(LocParseError::AddedParseError)?, ) }; let removed = if removed == "-" { @@ -426,7 +426,7 @@ impl Loc { Some( removed .parse() - .map_err(|err| LocParseError::RemovedParseError(err))?, + .map_err(LocParseError::RemovedParseError)?, ) }; let file = file.into(); From 50ce6125c717c138588c0d6e46391fe17fbfd7ff Mon Sep 17 00:00:00 2001 From: Kevin Matthes <92332892+kevinmatthes@users.noreply.github.com> Date: Fri, 20 May 2022 16:48:00 +0200 Subject: [PATCH 28/31] Move module import --- src/main.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main.rs b/src/main.rs index ff27639..339b89c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,4 @@ +use getopts::Options; use std::{collections::HashMap, error::Error, io::Write, num::ParseIntError, ops::AddAssign}; use usage::usage; From 575ece76d71a7da67abac71a0995bcce092f81dd Mon Sep 17 00:00:00 2001 From: Kevin Matthes <92332892+kevinmatthes@users.noreply.github.com> Date: Fri, 20 May 2022 16:50:44 +0200 Subject: [PATCH 29/31] Move function --- src/main.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index 339b89c..4e0122c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,8 +1,5 @@ use getopts::Options; use std::{collections::HashMap, error::Error, io::Write, num::ParseIntError, ops::AddAssign}; -use usage::usage; - -mod usage; fn main() -> Result<(), Box> { let mut opts = getopts::Options::new(); @@ -181,6 +178,17 @@ fn main() -> Result<(), Box> { Ok(()) } +/// A small in-app documentation. +/// +/// This function will write a brief usage information, including a short +/// introduction to the meaning of the configured `options`, to `stdout`. +fn usage(options: &Options) { + println!( + "Usage: commit-analyzer [OPTIONS]\n\n{}", + options.usage("Parses the output of `git log`.") + ); +} + fn matches_filter(commit: &Commit, filter: &Filter) -> bool { filter.check_author_name(&commit.author.name) && filter.check_author_email(&commit.author.email) From 750505d00f2bb437dc817eb3997575392a67abec Mon Sep 17 00:00:00 2001 From: Kevin Matthes <92332892+kevinmatthes@users.noreply.github.com> Date: Fri, 20 May 2022 16:50:56 +0200 Subject: [PATCH 30/31] Delete usage.rs --- src/usage.rs | 21 --------------------- 1 file changed, 21 deletions(-) delete mode 100644 src/usage.rs diff --git a/src/usage.rs b/src/usage.rs deleted file mode 100644 index 9c59b95..0000000 --- a/src/usage.rs +++ /dev/null @@ -1,21 +0,0 @@ -//! The module for the usage advice. -//! -//! The usage advice defined in this module is specialised regarding the needs -//! of this application. This is, -//! -//! * the application name is hard coded, -//! * the tool tip is hard coded, and -//! * the expected order of arguments in the usage template is hard coded. - -use getopts::Options; - -/// A small in-app documentation. -/// -/// This function will write a brief usage information, including a short -/// introduction to the meaning of the configured `options`, to `stdout`. -pub fn usage(options: &Options) { - println!( - "Usage: commit-analyzer [OPTIONS]\n\n{}", - options.usage("Parses the output of `git log`.") - ); -} From bcedceef4959abdd80b930e4c620d834d87e574d Mon Sep 17 00:00:00 2001 From: Kevin Matthes Date: Fri, 20 May 2022 16:56:41 +0200 Subject: [PATCH 31/31] Reformat code --- src/main.rs | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/main.rs b/src/main.rs index 4e0122c..49be9ec 100644 --- a/src/main.rs +++ b/src/main.rs @@ -423,20 +423,12 @@ impl Loc { let added = if added == "-" { None } else { - Some( - added - .parse() - .map_err(LocParseError::AddedParseError)?, - ) + Some(added.parse().map_err(LocParseError::AddedParseError)?) }; let removed = if removed == "-" { None } else { - Some( - removed - .parse() - .map_err(LocParseError::RemovedParseError)?, - ) + Some(removed.parse().map_err(LocParseError::RemovedParseError)?) }; let file = file.into(); Ok(Self {