Skip to content

Commit 7a60db5

Browse files
BenWiederhakesylvestre
authored andcommitted
date: forbid conflicting options
1 parent 4e29818 commit 7a60db5

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
@@ -319,6 +319,8 @@ pub fn uu_app() -> Command {
319319
.long(OPT_DATE)
320320
.value_name("STRING")
321321
.overrides_with(OPT_DATE)
322+
.conflicts_with(OPT_FILE)
323+
.conflicts_with(OPT_REFERENCE)
322324
.help("display time described by STRING, not 'now'"),
323325
)
324326
.arg(
@@ -328,6 +330,7 @@ pub fn uu_app() -> Command {
328330
.value_name("DATEFILE")
329331
.value_hint(clap::ValueHint::FilePath)
330332
.overrides_with(OPT_FILE)
333+
.conflicts_with(OPT_REFERENCE)
331334
.help("like --date; once for each line of DATEFILE"),
332335
)
333336
.arg(
@@ -340,13 +343,16 @@ pub fn uu_app() -> Command {
340343
]))
341344
.num_args(0..=1)
342345
.default_missing_value(OPT_DATE)
346+
.conflicts_with(OPT_RFC_EMAIL)
347+
.conflicts_with(OPT_RFC_3339)
343348
.help(ISO_8601_HELP_STRING),
344349
)
345350
.arg(
346351
Arg::new(OPT_RFC_EMAIL)
347352
.short('R')
348353
.long(OPT_RFC_EMAIL)
349354
.help(RFC_5322_HELP_STRING)
355+
.conflicts_with(OPT_RFC_3339)
350356
.action(ArgAction::SetTrue),
351357
)
352358
.arg(
@@ -378,6 +384,9 @@ pub fn uu_app() -> Command {
378384
.long(OPT_SET)
379385
.value_name("STRING")
380386
.overrides_with(OPT_SET)
387+
.conflicts_with(OPT_DATE)
388+
.conflicts_with(OPT_FILE)
389+
.conflicts_with(OPT_REFERENCE)
381390
.help(OPT_SET_HELP_STRING),
382391
)
383392
.arg(

tests/by-util/test_date.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,3 +595,27 @@ fn test_repeat_reference_older_last() {
595595
.stdout_only("2001-02-03\n")
596596
.no_stderr();
597597
}
598+
599+
#[test]
600+
fn test_incompatible_args() {
601+
for args in [
602+
// Input with other input
603+
vec!["-d", "now", "-f", "foo"],
604+
vec!["-d", "now", "-r", "foo"],
605+
vec!["-f", "foo", "-r", "foo"],
606+
// Format with other format
607+
vec!["-I", "-R"],
608+
vec!["-I", "--rfc-3339=date"],
609+
vec!["-R", "--rfc-3339=date"],
610+
// Input with --set
611+
vec!["-d", "now", "-s", "now"],
612+
vec!["-r", "foo", "-s", "now"],
613+
vec!["-f", "foo", "-s", "now"],
614+
] {
615+
new_ucmd!()
616+
.args(&args)
617+
.fails()
618+
.no_stdout()
619+
.stderr_contains(" cannot be used with ");
620+
}
621+
}

0 commit comments

Comments
 (0)