diff --git a/src/uu/hashsum/locales/en-US.ftl b/src/uu/hashsum/locales/en-US.ftl index d2efe72716b..2001a849181 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 ce900291803..a72ea98fcc5 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 aa3ab6f4f2c..a138d4e6b7d 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 --"); +}