Skip to content

Commit 3c821b2

Browse files
oech3oech3
authored andcommitted
cksum, hashsum: Manually error standalone --warn's and comment why
1 parent 30239e6 commit 3c821b2

File tree

2 files changed

+24
-19
lines changed

2 files changed

+24
-19
lines changed

src/uu/cksum/src/cksum.rs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,13 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
126126
.unwrap()
127127
.map(|s| s.as_os_str());
128128

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

180187
pub fn uu_app() -> Command {
188+
// --warn .requires(options::CHECK) allows bypassing --text --warn. We don't use it until clap 5
189+
// https://github.com/clap-rs/clap/issues/4520
190+
// even --untagged bypass the bug, we don't for hashsum deletion
181191
Command::new(uucore::util_name())
182192
.version(uucore::crate_version!())
183193
.help_template(uucore::localized_help_template(uucore::util_name()))
@@ -235,8 +245,7 @@ pub fn uu_app() -> Command {
235245
Arg::new(options::STRICT)
236246
.long(options::STRICT)
237247
.help(translate!("cksum-help-strict"))
238-
.action(ArgAction::SetTrue)
239-
.requires(options::CHECK),
248+
.action(ArgAction::SetTrue),
240249
)
241250
.arg(
242251
Arg::new(options::CHECK)
@@ -280,31 +289,27 @@ pub fn uu_app() -> Command {
280289
.long("warn")
281290
.help(translate!("cksum-help-warn"))
282291
.action(ArgAction::SetTrue)
283-
.overrides_with_all([options::STATUS, options::QUIET])
284-
.requires(options::CHECK),
292+
.overrides_with_all([options::STATUS, options::QUIET]),
285293
)
286294
.arg(
287295
Arg::new(options::STATUS)
288296
.long("status")
289297
.help(translate!("cksum-help-status"))
290298
.action(ArgAction::SetTrue)
291-
.overrides_with_all([options::WARN, options::QUIET])
292-
.requires(options::CHECK),
299+
.overrides_with_all([options::WARN, options::QUIET]),
293300
)
294301
.arg(
295302
Arg::new(options::QUIET)
296303
.long(options::QUIET)
297304
.help(translate!("cksum-help-quiet"))
298305
.action(ArgAction::SetTrue)
299-
.overrides_with_all([options::WARN, options::STATUS])
300-
.requires(options::CHECK),
306+
.overrides_with_all([options::WARN, options::STATUS]),
301307
)
302308
.arg(
303309
Arg::new(options::IGNORE_MISSING)
304310
.long(options::IGNORE_MISSING)
305311
.help(translate!("cksum-help-ignore-missing"))
306-
.action(ArgAction::SetTrue)
307-
.requires(options::CHECK),
312+
.action(ArgAction::SetTrue),
308313
)
309314
.arg(
310315
Arg::new(options::ZERO)

src/uu/hashsum/src/hashsum.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,13 @@ pub fn uumain(mut args: impl uucore::Args) -> UResult<()> {
169169
.unwrap()
170170
.map(|s| s.as_os_str());
171171

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

222229
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...
230+
// --warn .requires(options::CHECK) allows bypassing --text --warn. We don't use it until clap 5
231+
// https://github.com/clap-rs/clap/issues/4520
227232
Command::new(uucore::util_name())
228233
.version(uucore::crate_version!())
229234
.help_template(uucore::localized_help_template(uucore::util_name()))
@@ -288,7 +293,6 @@ pub fn uu_app_common() -> Command {
288293
.help(translate!("hashsum-help-quiet"))
289294
.action(ArgAction::SetTrue)
290295
.overrides_with_all([options::STATUS, options::WARN])
291-
.conflicts_with("text")
292296
.requires(options::CHECK),
293297
)
294298
.arg(
@@ -298,23 +302,20 @@ pub fn uu_app_common() -> Command {
298302
.help(translate!("hashsum-help-status"))
299303
.action(ArgAction::SetTrue)
300304
.overrides_with_all([options::QUIET, options::WARN])
301-
.conflicts_with("text")
302305
.requires(options::CHECK),
303306
)
304307
.arg(
305308
Arg::new(options::STRICT)
306309
.long("strict")
307310
.help(translate!("hashsum-help-strict"))
308311
.action(ArgAction::SetTrue)
309-
.conflicts_with("text")
310312
.requires(options::CHECK),
311313
)
312314
.arg(
313315
Arg::new("ignore-missing")
314316
.long("ignore-missing")
315317
.help(translate!("hashsum-help-ignore-missing"))
316318
.action(ArgAction::SetTrue)
317-
.conflicts_with("text")
318319
.requires(options::CHECK),
319320
)
320321
.arg(
@@ -324,7 +325,6 @@ pub fn uu_app_common() -> Command {
324325
.help(translate!("hashsum-help-warn"))
325326
.action(ArgAction::SetTrue)
326327
.overrides_with_all([options::QUIET, options::STATUS])
327-
.conflicts_with("text")
328328
.requires(options::CHECK),
329329
)
330330
.arg(

0 commit comments

Comments
 (0)