From cbf2e6bb7a115f82f07d513b4c1336e34457d6ee Mon Sep 17 00:00:00 2001 From: oech3 <> Date: Sun, 4 Jan 2026 12:37:12 +0900 Subject: [PATCH] hashsum, cksum: Move --ckeck confliction to clap --- src/uu/cksum/src/cksum.rs | 11 +++------ src/uu/hashsum/src/hashsum.rs | 26 ++++++++++----------- src/uucore/src/lib/features/checksum/mod.rs | 2 -- tests/by-util/test_cksum.rs | 4 ++-- 4 files changed, 18 insertions(+), 25 deletions(-) diff --git a/src/uu/cksum/src/cksum.rs b/src/uu/cksum/src/cksum.rs index 70c80ae37c7..3e8e147f4e0 100644 --- a/src/uu/cksum/src/cksum.rs +++ b/src/uu/cksum/src/cksum.rs @@ -134,14 +134,6 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { return Err(ChecksumError::AlgorithmNotSupportedWithCheck.into()); } - let text_flag = matches.get_flag(options::TEXT); - let binary_flag = matches.get_flag(options::BINARY); - let tag = matches.get_flag(options::TAG); - - if tag || binary_flag || text_flag { - return Err(ChecksumError::BinaryTextConflict.into()); - } - // Execute the checksum validation based on the presence of files or the use of stdin let verbose = ChecksumVerbose::new(status, quiet, warn); @@ -251,6 +243,9 @@ pub fn uu_app() -> Command { .short('c') .long(options::CHECK) .help(translate!("cksum-help-check")) + .conflicts_with(options::TAG) + .conflicts_with(options::BINARY) + .conflicts_with(options::TEXT) .action(ArgAction::SetTrue), ) .arg( diff --git a/src/uu/hashsum/src/hashsum.rs b/src/uu/hashsum/src/hashsum.rs index eea434d9477..963be70803c 100644 --- a/src/uu/hashsum/src/hashsum.rs +++ b/src/uu/hashsum/src/hashsum.rs @@ -171,18 +171,7 @@ pub fn uumain(mut args: impl uucore::Args) -> UResult<()> { ); if check { - // on Windows, allow --binary/--text to be used with --check - // and keep the behavior of defaulting to binary - #[cfg(not(windows))] - { - let text_flag = matches.get_flag("text"); - let binary_flag = matches.get_flag("binary"); - - if binary_flag || text_flag { - return Err(ChecksumError::BinaryTextConflict.into()); - } - } - + // No reason to allow --check with --binary/--text on Cygwin. It want to be same with Linux and --text was broken for a long time. let verbose = ChecksumVerbose::new(status, quiet, warn); let opts = ChecksumValidateOptions { @@ -232,6 +221,10 @@ mod options { } pub fn uu_app_common() -> Command { + // --text --arg-deps-check should be error by Arg::new(options::CHECK)...conflicts_with(options::TEXT) + // https://github.com/clap-rs/clap/issues/4520 ? + // Let --{warn,strict,quiet,status,ignore-missing} reject --text and remove them later. + // Bad error message, but not a lie... Command::new(uucore::util_name()) .version(uucore::crate_version!()) .help_template(uucore::localized_help_template(uucore::util_name())) @@ -261,7 +254,9 @@ pub fn uu_app_common() -> Command { .long("check") .help(translate!("hashsum-help-check")) .action(ArgAction::SetTrue) - .conflicts_with("tag"), + .conflicts_with(options::BINARY) + .conflicts_with(options::TEXT) + .conflicts_with(options::TAG), ) .arg( Arg::new(options::TAG) @@ -294,6 +289,7 @@ pub fn uu_app_common() -> Command { .help(translate!("hashsum-help-quiet")) .action(ArgAction::SetTrue) .overrides_with_all([options::STATUS, options::WARN]) + .conflicts_with("text") .requires(options::CHECK), ) .arg( @@ -303,6 +299,7 @@ pub fn uu_app_common() -> Command { .help(translate!("hashsum-help-status")) .action(ArgAction::SetTrue) .overrides_with_all([options::QUIET, options::WARN]) + .conflicts_with("text") .requires(options::CHECK), ) .arg( @@ -310,6 +307,7 @@ pub fn uu_app_common() -> Command { .long("strict") .help(translate!("hashsum-help-strict")) .action(ArgAction::SetTrue) + .conflicts_with("text") .requires(options::CHECK), ) .arg( @@ -317,6 +315,7 @@ pub fn uu_app_common() -> Command { .long("ignore-missing") .help(translate!("hashsum-help-ignore-missing")) .action(ArgAction::SetTrue) + .conflicts_with("text") .requires(options::CHECK), ) .arg( @@ -326,6 +325,7 @@ pub fn uu_app_common() -> Command { .help(translate!("hashsum-help-warn")) .action(ArgAction::SetTrue) .overrides_with_all([options::QUIET, options::STATUS]) + .conflicts_with("text") .requires(options::CHECK), ) .arg( diff --git a/src/uucore/src/lib/features/checksum/mod.rs b/src/uucore/src/lib/features/checksum/mod.rs index 7cf7fe129fa..e272cdea68b 100644 --- a/src/uucore/src/lib/features/checksum/mod.rs +++ b/src/uucore/src/lib/features/checksum/mod.rs @@ -390,8 +390,6 @@ pub enum ChecksumError { #[error("--length is only supported with --algorithm blake2b, sha2, or sha3")] LengthOnlyForBlake2bSha2Sha3, - #[error("the --binary and --text options are meaningless when verifying checksums")] - BinaryTextConflict, #[error("--text mode is only supported with --untagged")] TextWithoutUntagged, #[error("--check is not supported with --algorithm={{bsd,sysv,crc,crc32b}}")] diff --git a/tests/by-util/test_cksum.rs b/tests/by-util/test_cksum.rs index d1abe3409ba..40f49fc70f8 100644 --- a/tests/by-util/test_cksum.rs +++ b/tests/by-util/test_cksum.rs @@ -1216,7 +1216,7 @@ fn test_conflicting_options() { .fails_with_code(1) .no_stdout() .stderr_contains( - "cksum: the --binary and --text options are meaningless when verifying checksums", + "cannot be used with", //clap generated error ); scene @@ -1228,7 +1228,7 @@ fn test_conflicting_options() { .fails_with_code(1) .no_stdout() .stderr_contains( - "cksum: the --binary and --text options are meaningless when verifying checksums", + "cannot be used with", //clap generated error ); }