From b1edc49ef6680ec105fd9557d4509cf8b0e843e9 Mon Sep 17 00:00:00 2001 From: Dorian Peron Date: Fri, 9 Jan 2026 12:37:02 +0100 Subject: [PATCH] Revert "hashsum: Move --ckeck's deps to clap" This reverts commit c01e83eb76cc59e0a78eb2d5fa0ec99d80c4c44f. --- src/uu/hashsum/src/hashsum.rs | 33 ++++++++++++++++++--------------- tests/by-util/test_hashsum.rs | 6 +++--- util/build-gnu.sh | 2 -- 3 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/uu/hashsum/src/hashsum.rs b/src/uu/hashsum/src/hashsum.rs index 3bc6dcff5..1bad36355 100644 --- a/src/uu/hashsum/src/hashsum.rs +++ b/src/uu/hashsum/src/hashsum.rs @@ -157,11 +157,19 @@ pub fn uumain(mut args: impl uucore::Args) -> UResult<()> { }; let check = matches.get_flag("check"); - let ignore_missing = matches.get_flag("ignore-missing"); - let warn = matches.get_flag("warn"); - let quiet = matches.get_flag("quiet"); - let strict = matches.get_flag("strict"); - let status = matches.get_flag("status"); + let check_flag = |flag| match (check, matches.get_flag(flag)) { + (_, false) => Ok(false), + (true, true) => Ok(true), + (false, true) => Err(ChecksumError::CheckOnlyFlag(flag.into())), + }; + + // Each of the following flags are only expected in --check mode. + // If we encounter them otherwise, end with an error. + let ignore_missing = check_flag("ignore-missing")?; + let warn = check_flag("warn")?; + let quiet = check_flag("quiet")?; + let strict = check_flag("strict")?; + let status = check_flag("status")?; // clap provides the default value -. So we unwrap() safety. let files = matches @@ -292,8 +300,7 @@ pub fn uu_app_common() -> Command { .long(options::QUIET) .help(translate!("hashsum-help-quiet")) .action(ArgAction::SetTrue) - .overrides_with_all([options::STATUS, options::WARN]) - .requires(options::CHECK), + .overrides_with_all([options::STATUS, options::WARN]), ) .arg( Arg::new(options::STATUS) @@ -301,22 +308,19 @@ pub fn uu_app_common() -> Command { .long("status") .help(translate!("hashsum-help-status")) .action(ArgAction::SetTrue) - .overrides_with_all([options::QUIET, options::WARN]) - .requires(options::CHECK), + .overrides_with_all([options::QUIET, options::WARN]), ) .arg( Arg::new(options::STRICT) .long("strict") .help(translate!("hashsum-help-strict")) - .action(ArgAction::SetTrue) - .requires(options::CHECK), + .action(ArgAction::SetTrue), ) .arg( Arg::new("ignore-missing") .long("ignore-missing") .help(translate!("hashsum-help-ignore-missing")) - .action(ArgAction::SetTrue) - .requires(options::CHECK), + .action(ArgAction::SetTrue), ) .arg( Arg::new(options::WARN) @@ -324,8 +328,7 @@ pub fn uu_app_common() -> Command { .long("warn") .help(translate!("hashsum-help-warn")) .action(ArgAction::SetTrue) - .overrides_with_all([options::QUIET, options::STATUS]) - .requires(options::CHECK), + .overrides_with_all([options::QUIET, options::STATUS]), ) .arg( Arg::new("zero") diff --git a/tests/by-util/test_hashsum.rs b/tests/by-util/test_hashsum.rs index 891cb9d4d..2f1719b0e 100644 --- a/tests/by-util/test_hashsum.rs +++ b/tests/by-util/test_hashsum.rs @@ -268,7 +268,7 @@ fn test_check_md5_ignore_missing() { .arg("--ignore-missing") .arg(at.subdir.join("testf.sha1")) .fails() - .stderr_contains("the following required arguments were not provided"); //clap generated error + .stderr_contains("the --ignore-missing option is meaningful only when verifying checksums"); } #[test] @@ -1021,13 +1021,13 @@ fn test_check_quiet() { .arg("--quiet") .arg(at.subdir.join("in.md5")) .fails() - .stderr_contains("the following required arguments were not provided"); //clap generated error + .stderr_contains("md5sum: the --quiet option is meaningful only when verifying checksums"); scene .ccmd("md5sum") .arg("--strict") .arg(at.subdir.join("in.md5")) .fails() - .stderr_contains("the following required arguments were not provided"); //clap generated error + .stderr_contains("md5sum: the --strict option is meaningful only when verifying checksums"); } #[test] diff --git a/util/build-gnu.sh b/util/build-gnu.sh index 7102acd07..65abcc4fd 100755 --- a/util/build-gnu.sh +++ b/util/build-gnu.sh @@ -322,8 +322,6 @@ test \$n_stat1 -ge \$n_stat2 \\' tests/ls/stat-free-color.sh # no need to replicate this output with hashsum "${SED}" -i -e "s|Try 'md5sum --help' for more information.\\\n||" tests/cksum/md5sum.pl -# clap changes the error message - "${SED}" -i '/check-ignore-missing-4/,/EXIT=> 1/ { /ERR=>/,/try_help/d }' tests/cksum/md5sum.pl # Our ls command always outputs ANSI color codes prepended with a zero. However, # in the case of GNU, it seems inconsistent. Nevertheless, it looks like it