Skip to content

Commit 5264cb8

Browse files
BenWiederhakesylvestre
authored andcommitted
date: forbid conflicting options
1 parent 3befb16 commit 5264cb8

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

src/uu/date/src/date.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,8 @@ pub fn uu_app() -> Command {
326326
.long(OPT_DATE)
327327
.value_name("STRING")
328328
.overrides_with(OPT_DATE)
329+
.conflicts_with(OPT_FILE)
330+
.conflicts_with(OPT_REFERENCE)
329331
.help("display time described by STRING, not 'now'"),
330332
)
331333
.arg(
@@ -335,6 +337,7 @@ pub fn uu_app() -> Command {
335337
.value_name("DATEFILE")
336338
.value_hint(clap::ValueHint::FilePath)
337339
.overrides_with(OPT_FILE)
340+
.conflicts_with(OPT_REFERENCE)
338341
.help("like --date; once for each line of DATEFILE"),
339342
)
340343
.arg(
@@ -347,13 +350,16 @@ pub fn uu_app() -> Command {
347350
]))
348351
.num_args(0..=1)
349352
.default_missing_value(OPT_DATE)
353+
.conflicts_with(OPT_RFC_EMAIL)
354+
.conflicts_with(OPT_RFC_3339)
350355
.help(ISO_8601_HELP_STRING),
351356
)
352357
.arg(
353358
Arg::new(OPT_RFC_EMAIL)
354359
.short('R')
355360
.long(OPT_RFC_EMAIL)
356361
.help(RFC_5322_HELP_STRING)
362+
.conflicts_with(OPT_RFC_3339)
357363
.action(ArgAction::SetTrue),
358364
)
359365
.arg(
@@ -385,6 +391,9 @@ pub fn uu_app() -> Command {
385391
.long(OPT_SET)
386392
.value_name("STRING")
387393
.overrides_with(OPT_SET)
394+
.conflicts_with(OPT_DATE)
395+
.conflicts_with(OPT_FILE)
396+
.conflicts_with(OPT_REFERENCE)
388397
.help(OPT_SET_HELP_STRING),
389398
)
390399
.arg(

tests/by-util/test_date.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,3 +632,27 @@ fn test_repeat_reference_older_last() {
632632
.stdout_only("2001-02-03\n")
633633
.no_stderr();
634634
}
635+
636+
#[test]
637+
fn test_incompatible_args() {
638+
for args in [
639+
// Input with other input
640+
vec!["-d", "now", "-f", "foo"],
641+
vec!["-d", "now", "-r", "foo"],
642+
vec!["-f", "foo", "-r", "foo"],
643+
// Format with other format
644+
vec!["-I", "-R"],
645+
vec!["-I", "--rfc-3339=date"],
646+
vec!["-R", "--rfc-3339=date"],
647+
// Input with --set
648+
vec!["-d", "now", "-s", "now"],
649+
vec!["-r", "foo", "-s", "now"],
650+
vec!["-f", "foo", "-s", "now"],
651+
] {
652+
new_ucmd!()
653+
.args(&args)
654+
.fails()
655+
.no_stdout()
656+
.stderr_contains(" cannot be used with ");
657+
}
658+
}

0 commit comments

Comments
 (0)