Skip to content

Commit cf96ed9

Browse files
authored
Merge branch 'main' into panic-fix
2 parents 3ca7a85 + 154fcb1 commit cf96ed9

File tree

5 files changed

+43
-33
lines changed

5 files changed

+43
-33
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9+
## [0.2.0](https://github.com/alex289/git-commit-stats/compare/v0.1.23...v0.2.0) - 2025-03-03
10+
11+
### Other
12+
13+
- update readme
14+
- [**breaking**] use Option type of clap and manually handling default values
15+
- bump the dependencies group with 2 updates
16+
917
## [0.1.23](https://github.com/alex289/git-commit-stats/compare/v0.1.22...v0.1.23) - 2025-02-17
1018

1119
### Added

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "git-commit-stats"
3-
version = "0.1.23"
3+
version = "0.2.0"
44
edition = "2021"
55
authors = ["Alexander Konietzko <me@alexanderkonietzko.com>"]
66
license = "MIT"

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,15 @@ Usage: git-commit-stats [OPTIONS]
6767

6868
Options:
6969
-r, --repo-path <REPO_PATH>
70-
Path to the Git repository (default = current directory) [default: ]
70+
Path to the Git repository [default = current directory]
7171
-a, --after <AFTER>
72-
Commit hash which commits should be analyzed (default = all) [default: ]
72+
Commit hash which commits should be analyzed [default = all]
7373
-b, --before <BEFORE>
74-
Commit hash before which commits should be analyzed (default = all) [default: ]
74+
Commit hash before which commits should be analyzed [default = all]
7575
-u, --user <USER>
76-
User name for commit analysis (default = git config user.name) [default: ]
76+
User name for commit analysis [default = `git config user.name`]
7777
-t, --top-committers <TOP_COMMITTERS>
78-
Amount of of top committers to show (default = 3) [default: 3]
78+
Amount of of top committers to show [default = 3]
7979
-h, --help
8080
Print help
8181
-V, --version

src/main.rs

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,47 +7,45 @@ use std::{env, fs, process};
77
#[derive(Parser, Debug)]
88
#[command(author, version, about, long_about = None)]
99
struct Args {
10-
/// Path to the Git repository (default = current directory)
11-
#[arg(short, long, default_value = "")]
12-
repo_path: String,
10+
/// Path to the Git repository [default = current directory]
11+
#[arg(short, long)]
12+
repo_path: Option<String>,
1313

14-
/// Commit hash which commits should be analyzed (default = all)
15-
#[arg(short, long, default_value = "")]
16-
after: String,
14+
/// Commit hash which commits should be analyzed [default = all]
15+
#[arg(short, long)]
16+
after: Option<String>,
1717

18-
/// Commit hash before which commits should be analyzed (default = all)
19-
#[arg(short, long, default_value = "")]
20-
before: String,
18+
/// Commit hash before which commits should be analyzed [default = all]
19+
#[arg(short, long)]
20+
before: Option<String>,
2121

22-
/// User name for commit analysis (default = git config user.name)
23-
#[arg(short, long, default_value = "")]
24-
user: String,
22+
/// User name for commit analysis [default = `git config user.name`]
23+
#[arg(short, long)]
24+
user: Option<String>,
2525

26-
/// Amount of of top committers to show (default = 3)
27-
#[arg(short, long, default_value_t = 3)]
28-
top_committers: usize,
26+
/// Amount of of top committers to show [default = 3]
27+
#[arg(short, long)]
28+
top_committers: Option<usize>,
2929
}
3030

3131
fn main() {
3232
let args = Args::parse();
3333

34-
let current_dir = if !args.repo_path.is_empty() {
35-
args.repo_path.clone()
36-
} else {
37-
env::current_dir()
34+
let current_dir = match args.repo_path {
35+
Some(repo_path) => repo_path.clone(),
36+
None => env::current_dir()
3837
.expect("Failed to get current directory")
3938
.to_string_lossy()
40-
.to_string()
39+
.to_string(),
4140
};
4241

4342
if !check_directory_and_git(&current_dir) {
4443
process::exit(1);
4544
}
4645

47-
let user_name = if args.user.is_empty() {
48-
analyzer::get_user_name()
49-
} else {
50-
args.user.clone()
46+
let user_name = match args.user {
47+
Some(user) => user.clone(),
48+
None => analyzer::get_user_name(),
5149
};
5250

5351
if user_name.is_empty() {
@@ -62,7 +60,11 @@ fn main() {
6260
process::exit(1);
6361
}
6462

65-
let commits = analyzer::get_commits(&repo, &args.after, &args.before);
63+
let commits = analyzer::get_commits(
64+
&repo,
65+
&args.after.unwrap_or_default(),
66+
&args.before.unwrap_or_default(),
67+
);
6668

6769
if commits.is_err() {
6870
eprintln!("Error: Failed to get commits.");
@@ -81,7 +83,7 @@ fn main() {
8183
println!();
8284
analyzer::show_coding_habits(&commits_vec);
8385
println!();
84-
analyzer::show_top_committers(args.top_committers, &commits_vec);
86+
analyzer::show_top_committers(args.top_committers.unwrap_or(3), &commits_vec);
8587
}
8688

8789
/// Check if the specified path is a directory and a Git repository.

0 commit comments

Comments
 (0)