Skip to content

Commit 50dff10

Browse files
oech3oech3
authored andcommitted
hashsum: Allow --text --tag
1 parent a1de3ed commit 50dff10

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/uu/hashsum/src/hashsum.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,15 @@ pub fn uumain(mut args: impl uucore::Args) -> UResult<()> {
169169
.unwrap()
170170
.map(|s| s.as_os_str());
171171

172+
// clap's conflicts_with does each other. So we manually rejects --tag --text while we do --text --tag by clap.
173+
// cksum can do it naturally by clap via --untagged dep with correct message.
174+
if matches.get_flag(options::TEXT) && std::env::args().any(|x| x == "--tag") {
175+
return Err(uucore::error::UUsageError::new(
176+
1,
177+
"--tag --text is not allowed while --text --tag works (unrecommended)".to_string(),
178+
));
179+
}
180+
172181
if check {
173182
// 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.
174183
let verbose = ChecksumVerbose::new(status, quiet, warn);
@@ -262,7 +271,7 @@ pub fn uu_app_common() -> Command {
262271
.long("tag")
263272
.help(translate!("hashsum-help-tag"))
264273
.action(ArgAction::SetTrue)
265-
.conflicts_with("text"),
274+
.overrides_with(options::TEXT),
266275
)
267276
.arg(
268277
Arg::new(options::TEXT)

tests/by-util/test_hashsum.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,19 @@ fn test_conflicting_arg() {
606606
.fails_with_code(1);
607607
}
608608

609+
#[cfg(target_os = "linux")]
610+
#[test]
611+
fn test_text_tag_device() {
612+
let scene = TestScenario::new(util_name!());
613+
614+
scene
615+
.ccmd("md5sum")
616+
.arg("--text")
617+
.arg("--tag")
618+
.arg("/dev/null")
619+
.succeeds();
620+
}
621+
609622
#[test]
610623
fn test_tag() {
611624
let scene = TestScenario::new(util_name!());

0 commit comments

Comments
 (0)