Skip to content
Draft
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
25 changes: 15 additions & 10 deletions src/uu/cksum/src/cksum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,13 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
.unwrap()
.map(|s| s.as_os_str());

// This should be done by clap. But https://github.com/clap-rs/clap/issues/4520
if !check & (warn || strict || quiet || ignore_missing || status) {
return Err(uucore::error::UUsageError::new(
1,
"the following required arguments were not provided:\n--check".to_string(),
));
}
if check {
// cksum does not support '--check'ing legacy algorithms
if algo_cli.is_some_and(AlgoKind::is_legacy) {
Expand Down Expand Up @@ -178,6 +185,9 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
}

pub fn uu_app() -> Command {
// --warn .requires(options::CHECK) allows bypassing --text --warn. We don't use it until clap 5
// https://github.com/clap-rs/clap/issues/4520
// even --untagged bypass the bug, we don't for hashsum deletion
Command::new(uucore::util_name())
.version(uucore::crate_version!())
.help_template(uucore::localized_help_template(uucore::util_name()))
Expand Down Expand Up @@ -235,8 +245,7 @@ pub fn uu_app() -> Command {
Arg::new(options::STRICT)
.long(options::STRICT)
.help(translate!("cksum-help-strict"))
.action(ArgAction::SetTrue)
.requires(options::CHECK),
.action(ArgAction::SetTrue),
)
.arg(
Arg::new(options::CHECK)
Expand Down Expand Up @@ -280,31 +289,27 @@ pub fn uu_app() -> Command {
.long("warn")
.help(translate!("cksum-help-warn"))
.action(ArgAction::SetTrue)
.overrides_with_all([options::STATUS, options::QUIET])
.requires(options::CHECK),
.overrides_with_all([options::STATUS, options::QUIET]),
)
.arg(
Arg::new(options::STATUS)
.long("status")
.help(translate!("cksum-help-status"))
.action(ArgAction::SetTrue)
.overrides_with_all([options::WARN, options::QUIET])
.requires(options::CHECK),
.overrides_with_all([options::WARN, options::QUIET]),
)
.arg(
Arg::new(options::QUIET)
.long(options::QUIET)
.help(translate!("cksum-help-quiet"))
.action(ArgAction::SetTrue)
.overrides_with_all([options::WARN, options::STATUS])
.requires(options::CHECK),
.overrides_with_all([options::WARN, options::STATUS]),
)
.arg(
Arg::new(options::IGNORE_MISSING)
.long(options::IGNORE_MISSING)
.help(translate!("cksum-help-ignore-missing"))
.action(ArgAction::SetTrue)
.requires(options::CHECK),
.action(ArgAction::SetTrue),
)
.arg(
Arg::new(options::ZERO)
Expand Down
18 changes: 9 additions & 9 deletions src/uu/hashsum/src/hashsum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,13 @@ pub fn uumain(mut args: impl uucore::Args) -> UResult<()> {
.unwrap()
.map(|s| s.as_os_str());

// This should be done by clap. But https://github.com/clap-rs/clap/issues/4520
if !check & (warn || strict || quiet || ignore_missing || status) {
return Err(uucore::error::UUsageError::new(
1,
"the following required arguments were not provided:\n--check".to_string(),
));
}
if check {
// 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.
let verbose = ChecksumVerbose::new(status, quiet, warn);
Expand Down Expand Up @@ -220,10 +227,8 @@ mod options {
}

pub fn uu_app_common() -> Command {
// --text --arg-deps-check should be error by Arg::new(options::CHECK)...conflicts_with(options::TEXT)
// https://github.com/clap-rs/clap/issues/4520 ?
// Let --{warn,strict,quiet,status,ignore-missing} reject --text and remove them later.
// Bad error message, but not a lie...
// --warn .requires(options::CHECK) allows bypassing --text --warn. We don't use it until clap 5
// https://github.com/clap-rs/clap/issues/4520
Command::new(uucore::util_name())
.version(uucore::crate_version!())
.help_template(uucore::localized_help_template(uucore::util_name()))
Expand Down Expand Up @@ -288,7 +293,6 @@ pub fn uu_app_common() -> Command {
.help(translate!("hashsum-help-quiet"))
.action(ArgAction::SetTrue)
.overrides_with_all([options::STATUS, options::WARN])
.conflicts_with("text")
.requires(options::CHECK),
)
.arg(
Expand All @@ -298,23 +302,20 @@ pub fn uu_app_common() -> Command {
.help(translate!("hashsum-help-status"))
.action(ArgAction::SetTrue)
.overrides_with_all([options::QUIET, options::WARN])
.conflicts_with("text")
.requires(options::CHECK),
)
.arg(
Arg::new(options::STRICT)
.long("strict")
.help(translate!("hashsum-help-strict"))
.action(ArgAction::SetTrue)
.conflicts_with("text")
.requires(options::CHECK),
)
.arg(
Arg::new("ignore-missing")
.long("ignore-missing")
.help(translate!("hashsum-help-ignore-missing"))
.action(ArgAction::SetTrue)
.conflicts_with("text")
.requires(options::CHECK),
)
.arg(
Expand All @@ -324,7 +325,6 @@ pub fn uu_app_common() -> Command {
.help(translate!("hashsum-help-warn"))
.action(ArgAction::SetTrue)
.overrides_with_all([options::QUIET, options::STATUS])
.conflicts_with("text")
.requires(options::CHECK),
)
.arg(
Expand Down
Loading