mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
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 --<digest>'. 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
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)]
|
||||
|
||||
@@ -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>");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user