Skip to content

Commit 48ddf40

Browse files
committed
date: forbid conflicting options
1 parent 6afd8ad commit 48ddf40

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
@@ -624,3 +624,27 @@ fn test_repeat_reference_older_last() {
624624
.stdout_only("2001-02-03\n")
625625
.no_stderr();
626626
}
627+
628+
#[test]
629+
fn test_incompatible_args() {
630+
for args in [
631+
// Input with other input
632+
vec!["-d", "now", "-f", "foo"],
633+
vec!["-d", "now", "-r", "foo"],
634+
vec!["-f", "foo", "-r", "foo"],
635+
// Format with other format
636+
vec!["-I", "-R"],
637+
vec!["-I", "--rfc-3339=date"],
638+
vec!["-R", "--rfc-3339=date"],
639+
// Input with --set
640+
vec!["-d", "now", "-s", "now"],
641+
vec!["-r", "foo", "-s", "now"],
642+
vec!["-f", "foo", "-s", "now"],
643+
] {
644+
new_ucmd!()
645+
.args(&args)
646+
.fails()
647+
.no_stdout()
648+
.stderr_contains(" cannot be used with ");
649+
}
650+
}

0 commit comments

Comments
 (0)