From 7bca02c38f48c7d57f9ea94f99a5a6ff50539caf Mon Sep 17 00:00:00 2001 From: AnarchistHoneybun <74085528+AnarchistHoneybun@users.noreply.github.com> Date: Sun, 21 Sep 2025 20:55:39 +0530 Subject: [PATCH] hashsum: fix help text to show actual utility name (#8650) Fix all hashsum utilities (md5sum, b2sum, sha256sum, etc.) to display their actual name in help output instead of generic 'hashsum --'. Override help_template and usage for specific utilities while preserving the original hashsum behavior for the generic multicall case. Add test to verify help output shows correct utility names and prevent future regression. Fixes #8614 --- src/uu/hashsum/locales/en-US.ftl | 3 +++ src/uu/hashsum/src/hashsum.rs | 12 ++++++++- tests/by-util/test_hashsum.rs | 45 ++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 1 deletion(-) diff --git a/src/uu/hashsum/locales/en-US.ftl b/src/uu/hashsum/locales/en-US.ftl index d2efe7271..2001a8491 100644 --- a/src/uu/hashsum/locales/en-US.ftl +++ b/src/uu/hashsum/locales/en-US.ftl @@ -1,6 +1,9 @@ hashsum-about = Compute and check message digests. hashsum-usage = hashsum -- [OPTIONS]... [FILE]... +# Utility-specific usage template +hashsum-usage-specific = {$utility_name} [OPTION]... [FILE]... + # Help messages hashsum-help-binary-windows = read or check in binary mode (default) hashsum-help-binary-other = read in binary mode diff --git a/src/uu/hashsum/src/hashsum.rs b/src/uu/hashsum/src/hashsum.rs index ce9002918..a72ea98fc 100644 --- a/src/uu/hashsum/src/hashsum.rs +++ b/src/uu/hashsum/src/hashsum.rs @@ -498,7 +498,7 @@ pub fn uu_app_custom() -> Command { /// hashsum is handled differently in build.rs /// therefore, this is different from other utilities. fn uu_app(binary_name: &str) -> (Command, bool) { - match binary_name { + let (mut command, is_hashsum_bin) = match binary_name { // These all support the same options. "md5sum" | "sha1sum" | "sha224sum" | "sha256sum" | "sha384sum" | "sha512sum" => { (uu_app_common(), false) @@ -516,7 +516,17 @@ fn uu_app(binary_name: &str) -> (Command, bool) { "b3sum" => (uu_app_b3sum(), false), // We're probably just being called as `hashsum`, so give them everything. _ => (uu_app_custom(), true), + }; + + // If not called as generic hashsum, override the command name and usage + if !is_hashsum_bin { + let usage = translate!("hashsum-usage-specific", "utility_name" => binary_name); + command = command + .help_template(uucore::localized_help_template(binary_name)) + .override_usage(format_usage(&usage)); } + + (command, is_hashsum_bin) } #[allow(clippy::cognitive_complexity)] diff --git a/tests/by-util/test_hashsum.rs b/tests/by-util/test_hashsum.rs index aa3ab6f4f..a138d4e6b 100644 --- a/tests/by-util/test_hashsum.rs +++ b/tests/by-util/test_hashsum.rs @@ -1080,3 +1080,48 @@ fn test_check_sha256_binary() { .no_stderr() .stdout_is("binary.png: OK\n"); } + +#[test] +fn test_help_shows_correct_utility_name() { + // Test that help output shows the actual utility name instead of "hashsum" + let scene = TestScenario::new(util_name!()); + + // Test md5sum + scene + .ccmd("md5sum") + .arg("--help") + .succeeds() + .stdout_contains("Usage: md5sum") + .stdout_does_not_contain("Usage: hashsum"); + + // Test sha256sum + scene + .ccmd("sha256sum") + .arg("--help") + .succeeds() + .stdout_contains("Usage: sha256sum") + .stdout_does_not_contain("Usage: hashsum"); + + // Test b2sum + scene + .ccmd("b2sum") + .arg("--help") + .succeeds() + .stdout_contains("Usage: b2sum") + .stdout_does_not_contain("Usage: hashsum"); + + // Test b3sum + scene + .ccmd("b3sum") + .arg("--help") + .succeeds() + .stdout_contains("Usage: b3sum") + .stdout_does_not_contain("Usage: hashsum"); + + // Test that generic hashsum still shows the correct usage + scene + .ccmd("hashsum") + .arg("--help") + .succeeds() + .stdout_contains("Usage: hashsum --"); +}