Skip to content

Commit 27060d8

Browse files
authored
Merge pull request #10041 from oech3/hashsum-windows
hashsum, cksum: Move --check confliction to clap
2 parents 0f9c69b + cbf2e6b commit 27060d8

4 files changed

Lines changed: 18 additions & 25 deletions

File tree

src/uu/cksum/src/cksum.rs

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

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

145137
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
@@ -170,18 +170,7 @@ pub fn uumain(mut args: impl uucore::Args) -> UResult<()> {
170170
.map(|s| s.as_os_str());
171171

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

187176
let opts = ChecksumValidateOptions {
@@ -231,6 +220,10 @@ mod options {
231220
}
232221

233222
pub fn uu_app_common() -> Command {
223+
// --text --arg-deps-check should be error by Arg::new(options::CHECK)...conflicts_with(options::TEXT)
224+
// https://github.com/clap-rs/clap/issues/4520 ?
225+
// Let --{warn,strict,quiet,status,ignore-missing} reject --text and remove them later.
226+
// Bad error message, but not a lie...
234227
Command::new(uucore::util_name())
235228
.version(uucore::crate_version!())
236229
.help_template(uucore::localized_help_template(uucore::util_name()))
@@ -260,7 +253,9 @@ pub fn uu_app_common() -> Command {
260253
.long("check")
261254
.help(translate!("hashsum-help-check"))
262255
.action(ArgAction::SetTrue)
263-
.conflicts_with("tag"),
256+
.conflicts_with(options::BINARY)
257+
.conflicts_with(options::TEXT)
258+
.conflicts_with(options::TAG),
264259
)
265260
.arg(
266261
Arg::new(options::TAG)
@@ -293,6 +288,7 @@ pub fn uu_app_common() -> Command {
293288
.help(translate!("hashsum-help-quiet"))
294289
.action(ArgAction::SetTrue)
295290
.overrides_with_all([options::STATUS, options::WARN])
291+
.conflicts_with("text")
296292
.requires(options::CHECK),
297293
)
298294
.arg(
@@ -302,20 +298,23 @@ pub fn uu_app_common() -> Command {
302298
.help(translate!("hashsum-help-status"))
303299
.action(ArgAction::SetTrue)
304300
.overrides_with_all([options::QUIET, options::WARN])
301+
.conflicts_with("text")
305302
.requires(options::CHECK),
306303
)
307304
.arg(
308305
Arg::new(options::STRICT)
309306
.long("strict")
310307
.help(translate!("hashsum-help-strict"))
311308
.action(ArgAction::SetTrue)
309+
.conflicts_with("text")
312310
.requires(options::CHECK),
313311
)
314312
.arg(
315313
Arg::new("ignore-missing")
316314
.long("ignore-missing")
317315
.help(translate!("hashsum-help-ignore-missing"))
318316
.action(ArgAction::SetTrue)
317+
.conflicts_with("text")
319318
.requires(options::CHECK),
320319
)
321320
.arg(
@@ -325,6 +324,7 @@ pub fn uu_app_common() -> Command {
325324
.help(translate!("hashsum-help-warn"))
326325
.action(ArgAction::SetTrue)
327326
.overrides_with_all([options::QUIET, options::STATUS])
327+
.conflicts_with("text")
328328
.requires(options::CHECK),
329329
)
330330
.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)