diff --git a/src/uu/hashsum/src/hashsum.rs b/src/uu/hashsum/src/hashsum.rs index a13ec468436..d31c96701c5 100644 --- a/src/uu/hashsum/src/hashsum.rs +++ b/src/uu/hashsum/src/hashsum.rs @@ -169,6 +169,15 @@ pub fn uumain(mut args: impl uucore::Args) -> UResult<()> { .unwrap() .map(|s| s.as_os_str()); + // clap's conflicts_with does each other. So we manually rejects --tag --text while we do --text --tag by clap. + // cksum can do it naturally by clap via --untagged dep with correct message. + if matches.get_flag(options::TEXT) && std::env::args().any(|x| x == "--tag") { + return Err(uucore::error::UUsageError::new( + 1, + "--tag --text is not allowed while --text --tag works (unrecommended)".to_string(), + )); + } + if check { // 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); @@ -262,7 +271,7 @@ pub fn uu_app_common() -> Command { .long("tag") .help(translate!("hashsum-help-tag")) .action(ArgAction::SetTrue) - .conflicts_with("text"), + .overrides_with(options::TEXT), ) .arg( Arg::new(options::TEXT) diff --git a/tests/by-util/test_hashsum.rs b/tests/by-util/test_hashsum.rs index 891cb9d4dfd..fd3844b9f7a 100644 --- a/tests/by-util/test_hashsum.rs +++ b/tests/by-util/test_hashsum.rs @@ -606,6 +606,19 @@ fn test_conflicting_arg() { .fails_with_code(1); } +#[cfg(target_os = "linux")] +#[test] +fn test_text_tag_device() { + let scene = TestScenario::new(util_name!()); + + scene + .ccmd("md5sum") + .arg("--text") + .arg("--tag") + .arg("/dev/null") + .succeeds(); +} + #[test] fn test_tag() { let scene = TestScenario::new(util_name!());