From 0abb12c5e9ae767de74c34404d5247c14a784e76 Mon Sep 17 00:00:00 2001 From: hippi345 <13539685+hippi345@users.noreply.github.com> Date: Fri, 30 Oct 2026 15:38:24 +0000 Subject: [PATCH 1/3] Rename CLI option --reverse to --rotate Keep --reverse as a hidden clap alias for backward compatibility. Add CLI parsing tests and update changelog and manual. --- CHANGELOG.md | 2 ++ docs/manual.md | 1 + src/main.rs | 55 ++++++++++++++++++++++++++++++++++++++++++-------- 3 files changed, 50 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8a8cafd..6e871f5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [unreleased] - Next Date +### Changed +- Renamed CLI option `--reverse` to `--rotate` (`-r`). `--reverse` remains available as a hidden alias. ## [0.8.3] - 2026-10-29 ### Fixed diff --git a/docs/manual.md b/docs/manual.md index 83eb8bd..c6bf71c 100644 --- a/docs/manual.md +++ b/docs/manual.md @@ -96,6 +96,7 @@ FLAGS: automatically (e.g. when piping to a file). Overrides option '--color' --no-pager Use no pager (print everything at once without prompt). + -r, --rotate Rotate the graph 180 degrees. -S, --sparse Print a less compact graph: merge lines point to target lines rather than merge commits. --svg Render graph as SVG instead of text-based. diff --git a/src/main.rs b/src/main.rs index e972f45..7d91d95 100644 --- a/src/main.rs +++ b/src/main.rs @@ -66,7 +66,7 @@ fn from_args() -> Result<(), String> { ) } -fn match_args() -> ArgMatches { +fn build_cli() -> Command { // Declare command line argument interface for clap let app = Command::new("git-graph").version(crate_version!()).about( "Structured Git graphs for your branching model.\n \ @@ -87,12 +87,13 @@ fn match_args() -> ArgMatches { let app = add_wrap_args(app); let app = add_format_args(app); - let app = app + app .arg( - Arg::new("reverse") - .long("reverse") + Arg::new("rotate") + .long("rotate") .short('r') - .help("Reverse the order of commits.") + .alias("reverse") + .help("Rotate the graph 180 degrees.") .required(false) .num_args(0), ) @@ -148,10 +149,12 @@ fn match_args() -> ArgMatches { Only the subgraph between the merge-base and the tips is displayed.", ) .num_args(1..), - ); + ) +} +fn match_args() -> ArgMatches { // Return match of declared arguments with what is present on command line - app.get_matches() + build_cli().get_matches() } /// Return true if session should continue, false if it should exit now @@ -173,7 +176,7 @@ fn configure_session(ses: &mut Session, matches: &ArgMatches) -> Result) -> Result<(), String> { } }) } + +#[cfg(test)] +mod cli_tests { + use super::build_cli; + + #[test] + fn rotate_flag_sets_rotate() { + let matches = build_cli() + .try_get_matches_from(["git-graph", "--rotate"]) + .unwrap(); + assert!(matches.get_flag("rotate")); + } + + #[test] + fn rotate_short_flag_sets_rotate() { + let matches = build_cli() + .try_get_matches_from(["git-graph", "-r"]) + .unwrap(); + assert!(matches.get_flag("rotate")); + } + + #[test] + fn reverse_alias_sets_rotate() { + let matches = build_cli() + .try_get_matches_from(["git-graph", "--reverse"]) + .unwrap(); + assert!(matches.get_flag("rotate")); + } + + #[test] + fn help_lists_rotate_not_reverse() { + let help = build_cli().render_help().to_string(); + assert!(help.contains("--rotate")); + assert!(!help.contains("--reverse")); + } +} From 9264aa719c89b45021c106b42b528153c1e9e7fc Mon Sep 17 00:00:00 2001 From: hippi345 <13539685+hippi345@users.noreply.github.com> Date: Fri, 30 Oct 2026 18:38:48 +0000 Subject: [PATCH 2/3] Apply cargo fmt to src/main.rs --- src/main.rs | 119 ++++++++++++++++++++++++++-------------------------- 1 file changed, 59 insertions(+), 60 deletions(-) diff --git a/src/main.rs b/src/main.rs index 7d91d95..bd5a20c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -87,69 +87,68 @@ fn build_cli() -> Command { let app = add_wrap_args(app); let app = add_format_args(app); - app - .arg( - Arg::new("rotate") - .long("rotate") - .short('r') - .alias("reverse") - .help("Rotate the graph 180 degrees.") - .required(false) - .num_args(0), - ) - .arg( - Arg::new("local") - .long("local") - .short('l') - .help("Show only local branches, no remotes.") - .required(false) - .num_args(0), - ) - .arg( - Arg::new("svg") - .long("svg") - .help("Render graph as SVG instead of text-based.") - .required(false) - .num_args(0), - ) - .arg( - Arg::new("debug") - .long("debug") - .short('d') - .help("Additional debug output and graphics.") - .required(false) - .num_args(0), - ) - .arg( - Arg::new("sparse") - .long("sparse") - .short('S') - .help( - "Print a less compact graph: merge lines point to target lines\n\ + app.arg( + Arg::new("rotate") + .long("rotate") + .short('r') + .alias("reverse") + .help("Rotate the graph 180 degrees.") + .required(false) + .num_args(0), + ) + .arg( + Arg::new("local") + .long("local") + .short('l') + .help("Show only local branches, no remotes.") + .required(false) + .num_args(0), + ) + .arg( + Arg::new("svg") + .long("svg") + .help("Render graph as SVG instead of text-based.") + .required(false) + .num_args(0), + ) + .arg( + Arg::new("debug") + .long("debug") + .short('d') + .help("Additional debug output and graphics.") + .required(false) + .num_args(0), + ) + .arg( + Arg::new("sparse") + .long("sparse") + .short('S') + .help( + "Print a less compact graph: merge lines point to target lines\n\ rather than merge commits.", - ) - .required(false) - .num_args(0), - ) - .arg( - Arg::new("style") - .long("style") - .short('s') - .help( - "Output style. One of [normal/thin|round|bold|double|ascii].\n \ + ) + .required(false) + .num_args(0), + ) + .arg( + Arg::new("style") + .long("style") + .short('s') + .help( + "Output style. One of [normal/thin|round|bold|double|ascii].\n \ (First character can be used as abbreviation, e.g. '-s r')", - ) - .required(false) - .num_args(1), - ) - .arg( - Arg::new("refspecs") - .help( - "Branch names or refspecs to show.\n \ + ) + .required(false) + .num_args(1), + ) + .arg( + Arg::new("refspecs") + .help( + "Branch names or refspecs to show.\n \ Only the subgraph between the merge-base and the tips is displayed.", - ) - .num_args(1..), - ) + ) + .num_args(1..), + ) } fn match_args() -> ArgMatches { From f1650094ba58e1f042f92bc00d79df6b3e3e49b5 Mon Sep 17 00:00:00 2001 From: hippi345 <13539685+hippi345@users.noreply.github.com> Date: Sat, 31 Oct 2026 18:23:22 -0400 Subject: [PATCH 3/3] Keep two blank lines between releases in CHANGELOG --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e871f5..866a76d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Renamed CLI option `--reverse` to `--rotate` (`-r`). `--reverse` remains available as a hidden alias. + + ## [0.8.3] - 2026-10-29 ### Fixed