1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-27 19:17:43 +00:00

date: use ShortcutValueParser

This commit is contained in:
Daniel Hofstetter 2023-06-14 10:36:14 +02:00
parent 24b979c821
commit 643afbd731

View file

@ -26,14 +26,13 @@ use uucore::{format_usage, help_about, help_usage, show};
#[cfg(windows)] #[cfg(windows)]
use windows_sys::Win32::{Foundation::SYSTEMTIME, System::SystemInformation::SetSystemTime}; use windows_sys::Win32::{Foundation::SYSTEMTIME, System::SystemInformation::SetSystemTime};
use uucore::shortcut_value_parser::ShortcutValueParser;
// Options // Options
const DATE: &str = "date"; const DATE: &str = "date";
const HOURS: &str = "hours"; const HOURS: &str = "hours";
const MINUTES: &str = "minutes"; const MINUTES: &str = "minutes";
const SECONDS: &str = "seconds"; const SECONDS: &str = "seconds";
const HOUR: &str = "hour";
const MINUTE: &str = "minute";
const SECOND: &str = "second";
const NS: &str = "ns"; const NS: &str = "ns";
const ABOUT: &str = help_about!("date.md"); const ABOUT: &str = help_about!("date.md");
@ -110,9 +109,9 @@ enum Iso8601Format {
impl<'a> From<&'a str> for Iso8601Format { impl<'a> From<&'a str> for Iso8601Format {
fn from(s: &str) -> Self { fn from(s: &str) -> Self {
match s { match s {
HOURS | HOUR => Self::Hours, HOURS => Self::Hours,
MINUTES | MINUTE => Self::Minutes, MINUTES => Self::Minutes,
SECONDS | SECOND => Self::Seconds, SECONDS => Self::Seconds,
NS => Self::Ns, NS => Self::Ns,
DATE => Self::Date, DATE => Self::Date,
// Note: This is caught by clap via `possible_values` // Note: This is caught by clap via `possible_values`
@ -131,7 +130,7 @@ impl<'a> From<&'a str> for Rfc3339Format {
fn from(s: &str) -> Self { fn from(s: &str) -> Self {
match s { match s {
DATE => Self::Date, DATE => Self::Date,
SECONDS | SECOND => Self::Seconds, SECONDS => Self::Seconds,
NS => Self::Ns, NS => Self::Ns,
// Should be caught by clap // Should be caught by clap
_ => panic!("Invalid format: {s}"), _ => panic!("Invalid format: {s}"),
@ -317,7 +316,9 @@ pub fn uu_app() -> Command {
.short('I') .short('I')
.long(OPT_ISO_8601) .long(OPT_ISO_8601)
.value_name("FMT") .value_name("FMT")
.value_parser([DATE, HOUR, HOURS, MINUTE, MINUTES, SECOND, SECONDS, NS]) .value_parser(ShortcutValueParser::new([
DATE, HOURS, MINUTES, SECONDS, NS,
]))
.num_args(0..=1) .num_args(0..=1)
.default_missing_value(OPT_DATE) .default_missing_value(OPT_DATE)
.help(ISO_8601_HELP_STRING), .help(ISO_8601_HELP_STRING),
@ -333,7 +334,7 @@ pub fn uu_app() -> Command {
Arg::new(OPT_RFC_3339) Arg::new(OPT_RFC_3339)
.long(OPT_RFC_3339) .long(OPT_RFC_3339)
.value_name("FMT") .value_name("FMT")
.value_parser([DATE, SECOND, SECONDS, NS]) .value_parser(ShortcutValueParser::new([DATE, SECONDS, NS]))
.help(RFC_3339_HELP_STRING), .help(RFC_3339_HELP_STRING),
) )
.arg( .arg(