From bd6905cf59a91ab08ebda7faa0fecc48a3597d64 Mon Sep 17 00:00:00 2001 From: Surya Teja K Date: Fri, 17 Mar 2023 01:20:37 +0530 Subject: [PATCH] fix: match date -I error messages with GNU date (#4499) * date: use value_parser to improve errors * date: update panic! to unreachable inside impl From for Iso8601Format --- src/uu/date/src/date.rs | 5 +++-- tests/by-util/test_date.rs | 7 +++++++ 2 files changed, 10 insertions(+), 2 deletions(-) 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"] {