Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 15 additions & 18 deletions src/uu/hashsum/src/hashsum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,19 +157,11 @@ pub fn uumain(mut args: impl uucore::Args) -> UResult<()> {
};
let check = matches.get_flag("check");

let check_flag = |flag| match (check, matches.get_flag(flag)) {
(_, false) => Ok(false),
(true, true) => Ok(true),
(false, true) => Err(ChecksumError::CheckOnlyFlag(flag.into())),
};

// Each of the following flags are only expected in --check mode.
// If we encounter them otherwise, end with an error.
let ignore_missing = check_flag("ignore-missing")?;
let warn = check_flag("warn")?;
let quiet = check_flag("quiet")?;
let strict = check_flag("strict")?;
let status = check_flag("status")?;
let ignore_missing = matches.get_flag("ignore-missing");
let warn = matches.get_flag("warn");
let quiet = matches.get_flag("quiet");
let strict = matches.get_flag("strict");
let status = matches.get_flag("status");

let files = matches.get_many::<OsString>(options::FILE).map_or_else(
// No files given, read from stdin.
Expand Down Expand Up @@ -301,35 +293,40 @@ pub fn uu_app_common() -> Command {
.long(options::QUIET)
.help(translate!("hashsum-help-quiet"))
.action(ArgAction::SetTrue)
.overrides_with_all([options::STATUS, options::WARN]),
.overrides_with_all([options::STATUS, options::WARN])
.requires(options::CHECK),
)
.arg(
Arg::new(options::STATUS)
.short('s')
.long("status")
.help(translate!("hashsum-help-status"))
.action(ArgAction::SetTrue)
.overrides_with_all([options::QUIET, options::WARN]),
.overrides_with_all([options::QUIET, options::WARN])
.requires(options::CHECK),
)
.arg(
Arg::new(options::STRICT)
.long("strict")
.help(translate!("hashsum-help-strict"))
.action(ArgAction::SetTrue),
.action(ArgAction::SetTrue)
.requires(options::CHECK),
)
.arg(
Arg::new("ignore-missing")
.long("ignore-missing")
.help(translate!("hashsum-help-ignore-missing"))
.action(ArgAction::SetTrue),
.action(ArgAction::SetTrue)
.requires(options::CHECK),
)
.arg(
Arg::new(options::WARN)
.short('w')
.long("warn")
.help(translate!("hashsum-help-warn"))
.action(ArgAction::SetTrue)
.overrides_with_all([options::QUIET, options::STATUS]),
.overrides_with_all([options::QUIET, options::STATUS])
.requires(options::CHECK),
)
.arg(
Arg::new("zero")
Expand Down
6 changes: 3 additions & 3 deletions tests/by-util/test_hashsum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ fn test_check_md5_ignore_missing() {
.arg("--ignore-missing")
.arg(at.subdir.join("testf.sha1"))
.fails()
.stderr_contains("the --ignore-missing option is meaningful only when verifying checksums");
.stderr_contains("the following required arguments were not provided"); //clap generated error
}

#[test]
Expand Down Expand Up @@ -1021,13 +1021,13 @@ fn test_check_quiet() {
.arg("--quiet")
.arg(at.subdir.join("in.md5"))
.fails()
.stderr_contains("md5sum: the --quiet option is meaningful only when verifying checksums");
.stderr_contains("the following required arguments were not provided"); //clap generated error
scene
.ccmd("md5sum")
.arg("--strict")
.arg(at.subdir.join("in.md5"))
.fails()
.stderr_contains("md5sum: the --strict option is meaningful only when verifying checksums");
.stderr_contains("the following required arguments were not provided"); //clap generated error
}

#[test]
Expand Down
2 changes: 2 additions & 0 deletions util/build-gnu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,8 @@ test \$n_stat1 -ge \$n_stat2 \\' tests/ls/stat-free-color.sh

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

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