Skip to content

Commit

Permalink
date: forbid conflicting options
Browse files Browse the repository at this point in the history
  • Loading branch information
BenWiederhake committed May 2, 2024
1 parent 531496e commit 0d0847a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/uu/date/src/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,8 @@ pub fn uu_app() -> Command {
.long(OPT_DATE)
.value_name("STRING")
.overrides_with(OPT_DATE)

Check warning on line 330 in src/uu/date/src/date.rs

View check run for this annotation

Codecov / codecov/patch

src/uu/date/src/date.rs#L330

Added line #L330 was not covered by tests
.conflicts_with(OPT_FILE)
.conflicts_with(OPT_REFERENCE)
.help("display time described by STRING, not 'now'"),
)
.arg(
Expand All @@ -337,6 +339,7 @@ pub fn uu_app() -> Command {
.value_name("DATEFILE")
.value_hint(clap::ValueHint::FilePath)
.overrides_with(OPT_FILE)
.conflicts_with(OPT_REFERENCE)
.help("like --date; once for each line of DATEFILE"),
)
.arg(
Expand All @@ -349,13 +352,16 @@ pub fn uu_app() -> Command {
]))
.num_args(0..=1)
.default_missing_value(OPT_DATE)
.conflicts_with(OPT_RFC_EMAIL)
.conflicts_with(OPT_RFC_3339)
.help(ISO_8601_HELP_STRING),
)
.arg(
Arg::new(OPT_RFC_EMAIL)
.short('R')
.long(OPT_RFC_EMAIL)
.help(RFC_5322_HELP_STRING)
.conflicts_with(OPT_RFC_3339)
.action(ArgAction::SetTrue),
)
.arg(
Expand Down Expand Up @@ -387,6 +393,9 @@ pub fn uu_app() -> Command {
.long(OPT_SET)
.value_name("STRING")
.overrides_with(OPT_SET)
.conflicts_with(OPT_DATE)
.conflicts_with(OPT_FILE)
.conflicts_with(OPT_REFERENCE)

Check warning on line 398 in src/uu/date/src/date.rs

View check run for this annotation

Codecov / codecov/patch

src/uu/date/src/date.rs#L397-L398

Added lines #L397 - L398 were not covered by tests
.help(OPT_SET_HELP_STRING),
)
.arg(
Expand Down
24 changes: 24 additions & 0 deletions tests/by-util/test_date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -613,3 +613,27 @@ fn test_repeat_reference_older_last() {
.stdout_only("2001-02-03\n")
.no_stderr();
}

#[test]
fn test_incompatible_args() {
for args in [
// Input with other input
vec!["-d", "now", "-f", "foo"],
vec!["-d", "now", "-r", "foo"],
vec!["-f", "foo", "-r", "foo"],
// Format with other format
vec!["-I", "-R"],
vec!["-I", "--rfc-3339=date"],
vec!["-R", "--rfc-3339=date"],
// Input with --set
vec!["-d", "now", "-s", "now"],
vec!["-r", "foo", "-s", "now"],
vec!["-f", "foo", "-s", "now"],
] {
new_ucmd!()
.args(&args)
.fails()
.no_stdout()
.stderr_contains(" cannot be used with ");
}
}

0 comments on commit 0d0847a

Please sign in to comment.