Skip to content

Commit cbf2e6b

Browse files
author
oech3
committed
hashsum, cksum: Move --ckeck confliction to clap
1 parent 44e0bba commit cbf2e6b

File tree

4 files changed

+18
-25
lines changed

4 files changed

+18
-25
lines changed

src/uu/cksum/src/cksum.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -134,14 +134,6 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
134134
return Err(ChecksumError::AlgorithmNotSupportedWithCheck.into());
135135
}
136136

137-
let text_flag = matches.get_flag(options::TEXT);
138-
let binary_flag = matches.get_flag(options::BINARY);
139-
let tag = matches.get_flag(options::TAG);
140-
141-
if tag || binary_flag || text_flag {
142-
return Err(ChecksumError::BinaryTextConflict.into());
143-
}
144-
145137
// Execute the checksum validation based on the presence of files or the use of stdin
146138

147139
let verbose = ChecksumVerbose::new(status, quiet, warn);
@@ -251,6 +243,9 @@ pub fn uu_app() -> Command {
251243
.short('c')
252244
.long(options::CHECK)
253245
.help(translate!("cksum-help-check"))
246+
.conflicts_with(options::TAG)
247+
.conflicts_with(options::BINARY)
248+
.conflicts_with(options::TEXT)
254249
.action(ArgAction::SetTrue),
255250
)
256251
.arg(

src/uu/hashsum/src/hashsum.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -171,18 +171,7 @@ pub fn uumain(mut args: impl uucore::Args) -> UResult<()> {
171171
);
172172

173173
if check {
174-
// on Windows, allow --binary/--text to be used with --check
175-
// and keep the behavior of defaulting to binary
176-
#[cfg(not(windows))]
177-
{
178-
let text_flag = matches.get_flag("text");
179-
let binary_flag = matches.get_flag("binary");
180-
181-
if binary_flag || text_flag {
182-
return Err(ChecksumError::BinaryTextConflict.into());
183-
}
184-
}
185-
174+
// 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.
186175
let verbose = ChecksumVerbose::new(status, quiet, warn);
187176

188177
let opts = ChecksumValidateOptions {
@@ -232,6 +221,10 @@ mod options {
232221
}
233222

234223
pub fn uu_app_common() -> Command {
224+
// --text --arg-deps-check should be error by Arg::new(options::CHECK)...conflicts_with(options::TEXT)
225+
// https://github.com/clap-rs/clap/issues/4520 ?
226+
// Let --{warn,strict,quiet,status,ignore-missing} reject --text and remove them later.
227+
// Bad error message, but not a lie...
235228
Command::new(uucore::util_name())
236229
.version(uucore::crate_version!())
237230
.help_template(uucore::localized_help_template(uucore::util_name()))
@@ -261,7 +254,9 @@ pub fn uu_app_common() -> Command {
261254
.long("check")
262255
.help(translate!("hashsum-help-check"))
263256
.action(ArgAction::SetTrue)
264-
.conflicts_with("tag"),
257+
.conflicts_with(options::BINARY)
258+
.conflicts_with(options::TEXT)
259+
.conflicts_with(options::TAG),
265260
)
266261
.arg(
267262
Arg::new(options::TAG)
@@ -294,6 +289,7 @@ pub fn uu_app_common() -> Command {
294289
.help(translate!("hashsum-help-quiet"))
295290
.action(ArgAction::SetTrue)
296291
.overrides_with_all([options::STATUS, options::WARN])
292+
.conflicts_with("text")
297293
.requires(options::CHECK),
298294
)
299295
.arg(
@@ -303,20 +299,23 @@ pub fn uu_app_common() -> Command {
303299
.help(translate!("hashsum-help-status"))
304300
.action(ArgAction::SetTrue)
305301
.overrides_with_all([options::QUIET, options::WARN])
302+
.conflicts_with("text")
306303
.requires(options::CHECK),
307304
)
308305
.arg(
309306
Arg::new(options::STRICT)
310307
.long("strict")
311308
.help(translate!("hashsum-help-strict"))
312309
.action(ArgAction::SetTrue)
310+
.conflicts_with("text")
313311
.requires(options::CHECK),
314312
)
315313
.arg(
316314
Arg::new("ignore-missing")
317315
.long("ignore-missing")
318316
.help(translate!("hashsum-help-ignore-missing"))
319317
.action(ArgAction::SetTrue)
318+
.conflicts_with("text")
320319
.requires(options::CHECK),
321320
)
322321
.arg(
@@ -326,6 +325,7 @@ pub fn uu_app_common() -> Command {
326325
.help(translate!("hashsum-help-warn"))
327326
.action(ArgAction::SetTrue)
328327
.overrides_with_all([options::QUIET, options::STATUS])
328+
.conflicts_with("text")
329329
.requires(options::CHECK),
330330
)
331331
.arg(

src/uucore/src/lib/features/checksum/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,8 +390,6 @@ pub enum ChecksumError {
390390
#[error("--length is only supported with --algorithm blake2b, sha2, or sha3")]
391391
LengthOnlyForBlake2bSha2Sha3,
392392

393-
#[error("the --binary and --text options are meaningless when verifying checksums")]
394-
BinaryTextConflict,
395393
#[error("--text mode is only supported with --untagged")]
396394
TextWithoutUntagged,
397395
#[error("--check is not supported with --algorithm={{bsd,sysv,crc,crc32b}}")]

tests/by-util/test_cksum.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,7 +1216,7 @@ fn test_conflicting_options() {
12161216
.fails_with_code(1)
12171217
.no_stdout()
12181218
.stderr_contains(
1219-
"cksum: the --binary and --text options are meaningless when verifying checksums",
1219+
"cannot be used with", //clap generated error
12201220
);
12211221

12221222
scene
@@ -1228,7 +1228,7 @@ fn test_conflicting_options() {
12281228
.fails_with_code(1)
12291229
.no_stdout()
12301230
.stderr_contains(
1231-
"cksum: the --binary and --text options are meaningless when verifying checksums",
1231+
"cannot be used with", //clap generated error
12321232
);
12331233
}
12341234

0 commit comments

Comments
 (0)