Skip to content

Commit ce58025

Browse files
authored
Merge pull request #9998 from oech3/hashsum-clap
hashsum: Move --ckeck's deps to clap
2 parents 23f1a1e + c01e83e commit ce58025

File tree

3 files changed

+20
-21
lines changed

3 files changed

+20
-21
lines changed

src/uu/hashsum/src/hashsum.rs

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

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")?;
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");
173165

174166
let files = matches.get_many::<OsString>(options::FILE).map_or_else(
175167
// No files given, read from stdin.
@@ -301,35 +293,40 @@ pub fn uu_app_common() -> Command {
301293
.long(options::QUIET)
302294
.help(translate!("hashsum-help-quiet"))
303295
.action(ArgAction::SetTrue)
304-
.overrides_with_all([options::STATUS, options::WARN]),
296+
.overrides_with_all([options::STATUS, options::WARN])
297+
.requires(options::CHECK),
305298
)
306299
.arg(
307300
Arg::new(options::STATUS)
308301
.short('s')
309302
.long("status")
310303
.help(translate!("hashsum-help-status"))
311304
.action(ArgAction::SetTrue)
312-
.overrides_with_all([options::QUIET, options::WARN]),
305+
.overrides_with_all([options::QUIET, options::WARN])
306+
.requires(options::CHECK),
313307
)
314308
.arg(
315309
Arg::new(options::STRICT)
316310
.long("strict")
317311
.help(translate!("hashsum-help-strict"))
318-
.action(ArgAction::SetTrue),
312+
.action(ArgAction::SetTrue)
313+
.requires(options::CHECK),
319314
)
320315
.arg(
321316
Arg::new("ignore-missing")
322317
.long("ignore-missing")
323318
.help(translate!("hashsum-help-ignore-missing"))
324-
.action(ArgAction::SetTrue),
319+
.action(ArgAction::SetTrue)
320+
.requires(options::CHECK),
325321
)
326322
.arg(
327323
Arg::new(options::WARN)
328324
.short('w')
329325
.long("warn")
330326
.help(translate!("hashsum-help-warn"))
331327
.action(ArgAction::SetTrue)
332-
.overrides_with_all([options::QUIET, options::STATUS]),
328+
.overrides_with_all([options::QUIET, options::STATUS])
329+
.requires(options::CHECK),
333330
)
334331
.arg(
335332
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 --ignore-missing option is meaningful only when verifying checksums");
271+
.stderr_contains("the following required arguments were not provided"); //clap generated error
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("md5sum: the --quiet option is meaningful only when verifying checksums");
1024+
.stderr_contains("the following required arguments were not provided"); //clap generated error
10251025
scene
10261026
.ccmd("md5sum")
10271027
.arg("--strict")
10281028
.arg(at.subdir.join("in.md5"))
10291029
.fails()
1030-
.stderr_contains("md5sum: the --strict option is meaningful only when verifying checksums");
1030+
.stderr_contains("the following required arguments were not provided"); //clap generated error
10311031
}
10321032

10331033
#[test]

util/build-gnu.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,8 @@ 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
325327

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

0 commit comments

Comments
 (0)