diff --git a/src/uu/date/src/date.rs b/src/uu/date/src/date.rs index 50736b2da..9368ef91f 100644 --- a/src/uu/date/src/date.rs +++ b/src/uu/date/src/date.rs @@ -114,8 +114,8 @@ impl<'a> From<&'a str> for Iso8601Format { SECONDS | SECOND => Self::Seconds, NS => Self::Ns, DATE => Self::Date, - // Should be caught by clap - _ => panic!("Invalid format: {s}"), + // Note: This is caught by clap via `possible_values` + _ => unreachable!(), } } } @@ -291,6 +291,7 @@ pub fn uu_app() -> Command { .short('I') .long(OPT_ISO_8601) .value_name("FMT") + .value_parser([DATE, HOUR, HOURS, MINUTE, MINUTES, SECOND, SECONDS, NS]) .help(ISO_8601_HELP_STRING), ) .arg( diff --git a/tests/by-util/test_date.rs b/tests/by-util/test_date.rs index a1064a8fa..6f471bb3e 100644 --- a/tests/by-util/test_date.rs +++ b/tests/by-util/test_date.rs @@ -50,6 +50,13 @@ fn test_date_rfc_8601() { } } +#[test] +fn test_date_rfc_8601_invalid_arg() { + for param in ["--iso-8601", "--i"] { + new_ucmd!().arg(format!("{param}=@")).fails(); + } +} + #[test] fn test_date_rfc_8601_second() { for param in ["--iso-8601", "--i"] {