Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/uu/hashsum/locales/en-US.ftl
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
hashsum-about = Compute and check message digests.
hashsum-usage = hashsum --<digest> [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
Expand Down
12 changes: 11 additions & 1 deletion src/uu/hashsum/src/hashsum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)]
Expand Down
45 changes: 45 additions & 0 deletions tests/by-util/test_hashsum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 --<digest>");
}
Loading