Skip to content

Commit b1edc49

Browse files
committed
Revert "hashsum: Move --ckeck's deps to clap"
This reverts commit c01e83e.
1 parent 0de3871 commit b1edc49

3 files changed

Lines changed: 21 additions & 20 deletions

File tree

src/uu/hashsum/src/hashsum.rs

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,19 @@ pub fn uumain(mut args: impl uucore::Args) -> UResult<()> {
157157
};
158158
let check = matches.get_flag("check");
159159

160-
let ignore_missing = matches.get_flag("ignore-missing");
161-
let warn = matches.get_flag("warn");
162-
let quiet = matches.get_flag("quiet");
163-
let strict = matches.get_flag("strict");
164-
let status = matches.get_flag("status");
160+
let check_flag = |flag| match (check, matches.get_flag(flag)) {
161+
(_, false) => Ok(false),
162+
(true, true) => Ok(true),
163+
(false, true) => Err(ChecksumError::CheckOnlyFlag(flag.into())),
164+
};
165+
166+
// Each of the following flags are only expected in --check mode.
167+
// If we encounter them otherwise, end with an error.
168+
let ignore_missing = check_flag("ignore-missing")?;
169+
let warn = check_flag("warn")?;
170+
let quiet = check_flag("quiet")?;
171+
let strict = check_flag("strict")?;
172+
let status = check_flag("status")?;
165173

166174
// clap provides the default value -. So we unwrap() safety.
167175
let files = matches
@@ -292,40 +300,35 @@ pub fn uu_app_common() -> Command {
292300
.long(options::QUIET)
293301
.help(translate!("hashsum-help-quiet"))
294302
.action(ArgAction::SetTrue)
295-
.overrides_with_all([options::STATUS, options::WARN])
296-
.requires(options::CHECK),
303+
.overrides_with_all([options::STATUS, options::WARN]),
297304
)
298305
.arg(
299306
Arg::new(options::STATUS)
300307
.short('s')
301308
.long("status")
302309
.help(translate!("hashsum-help-status"))
303310
.action(ArgAction::SetTrue)
304-
.overrides_with_all([options::QUIET, options::WARN])
305-
.requires(options::CHECK),
311+
.overrides_with_all([options::QUIET, options::WARN]),
306312
)
307313
.arg(
308314
Arg::new(options::STRICT)
309315
.long("strict")
310316
.help(translate!("hashsum-help-strict"))
311-
.action(ArgAction::SetTrue)
312-
.requires(options::CHECK),
317+
.action(ArgAction::SetTrue),
313318
)
314319
.arg(
315320
Arg::new("ignore-missing")
316321
.long("ignore-missing")
317322
.help(translate!("hashsum-help-ignore-missing"))
318-
.action(ArgAction::SetTrue)
319-
.requires(options::CHECK),
323+
.action(ArgAction::SetTrue),
320324
)
321325
.arg(
322326
Arg::new(options::WARN)
323327
.short('w')
324328
.long("warn")
325329
.help(translate!("hashsum-help-warn"))
326330
.action(ArgAction::SetTrue)
327-
.overrides_with_all([options::QUIET, options::STATUS])
328-
.requires(options::CHECK),
331+
.overrides_with_all([options::QUIET, options::STATUS]),
329332
)
330333
.arg(
331334
Arg::new("zero")

tests/by-util/test_hashsum.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ fn test_check_md5_ignore_missing() {
268268
.arg("--ignore-missing")
269269
.arg(at.subdir.join("testf.sha1"))
270270
.fails()
271-
.stderr_contains("the following required arguments were not provided"); //clap generated error
271+
.stderr_contains("the --ignore-missing option is meaningful only when verifying checksums");
272272
}
273273

274274
#[test]
@@ -1021,13 +1021,13 @@ fn test_check_quiet() {
10211021
.arg("--quiet")
10221022
.arg(at.subdir.join("in.md5"))
10231023
.fails()
1024-
.stderr_contains("the following required arguments were not provided"); //clap generated error
1024+
.stderr_contains("md5sum: the --quiet option is meaningful only when verifying checksums");
10251025
scene
10261026
.ccmd("md5sum")
10271027
.arg("--strict")
10281028
.arg(at.subdir.join("in.md5"))
10291029
.fails()
1030-
.stderr_contains("the following required arguments were not provided"); //clap generated error
1030+
.stderr_contains("md5sum: the --strict option is meaningful only when verifying checksums");
10311031
}
10321032

10331033
#[test]

util/build-gnu.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,8 +322,6 @@ test \$n_stat1 -ge \$n_stat2 \\' tests/ls/stat-free-color.sh
322322

323323
# no need to replicate this output with hashsum
324324
"${SED}" -i -e "s|Try 'md5sum --help' for more information.\\\n||" tests/cksum/md5sum.pl
325-
# clap changes the error message
326-
"${SED}" -i '/check-ignore-missing-4/,/EXIT=> 1/ { /ERR=>/,/try_help/d }' tests/cksum/md5sum.pl
327325

328326
# Our ls command always outputs ANSI color codes prepended with a zero. However,
329327
# in the case of GNU, it seems inconsistent. Nevertheless, it looks like it

0 commit comments

Comments
 (0)