1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-09-16 11:46:17 +00:00

date: update to clap 4

This commit is contained in:
Terts Diepraam 2022-09-29 16:40:12 +02:00
parent 5556d23e21
commit 8183f4cf06
2 changed files with 12 additions and 15 deletions

View file

@ -16,7 +16,7 @@ path = "src/date.rs"
[dependencies] [dependencies]
chrono = { version="^0.4.19", default-features=false, features=["std", "alloc", "clock"]} chrono = { version="^0.4.19", default-features=false, features=["std", "alloc", "clock"]}
clap = { version = "3.2", features = ["wrap_help", "cargo"] } clap = { version = "4.0", features = ["wrap_help", "cargo"] }
uucore = { version=">=0.0.16", package="uucore", path="../../uucore" } uucore = { version=">=0.0.16", package="uucore", path="../../uucore" }
[target.'cfg(unix)'.dependencies] [target.'cfg(unix)'.dependencies]

View file

@ -11,7 +11,7 @@
use chrono::{DateTime, FixedOffset, Local, Offset, Utc}; use chrono::{DateTime, FixedOffset, Local, Offset, Utc};
#[cfg(windows)] #[cfg(windows)]
use chrono::{Datelike, Timelike}; use chrono::{Datelike, Timelike};
use clap::{crate_version, Arg, Command}; use clap::{crate_version, Arg, ArgAction, Command};
#[cfg(all(unix, not(target_os = "macos"), not(target_os = "redox")))] #[cfg(all(unix, not(target_os = "macos"), not(target_os = "redox")))]
use libc::{clock_settime, timespec, CLOCK_REALTIME}; use libc::{clock_settime, timespec, CLOCK_REALTIME};
use std::fs::File; use std::fs::File;
@ -160,7 +160,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
.map(|mut iter| iter.next().unwrap_or(&DATE.to_string()).as_str().into()) .map(|mut iter| iter.next().unwrap_or(&DATE.to_string()).as_str().into())
{ {
Format::Iso8601(fmt) Format::Iso8601(fmt)
} else if matches.contains_id(OPT_RFC_EMAIL) { } else if matches.get_flag(OPT_RFC_EMAIL) {
Format::Rfc5322 Format::Rfc5322
} else if let Some(fmt) = matches } else if let Some(fmt) = matches
.get_one::<String>(OPT_RFC_3339) .get_one::<String>(OPT_RFC_3339)
@ -191,7 +191,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
}; };
let settings = Settings { let settings = Settings {
utc: matches.contains_id(OPT_UNIVERSAL), utc: matches.get_flag(OPT_UNIVERSAL),
format, format,
date_source, date_source,
set_to, set_to,
@ -257,7 +257,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
Ok(()) Ok(())
} }
pub fn uu_app<'a>() -> Command<'a> { pub fn uu_app() -> Command {
Command::new(uucore::util_name()) Command::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
@ -267,7 +267,6 @@ pub fn uu_app<'a>() -> Command<'a> {
Arg::new(OPT_DATE) Arg::new(OPT_DATE)
.short('d') .short('d')
.long(OPT_DATE) .long(OPT_DATE)
.takes_value(true)
.value_name("STRING") .value_name("STRING")
.help("display time described by STRING, not 'now'"), .help("display time described by STRING, not 'now'"),
) )
@ -275,7 +274,6 @@ pub fn uu_app<'a>() -> Command<'a> {
Arg::new(OPT_FILE) Arg::new(OPT_FILE)
.short('f') .short('f')
.long(OPT_FILE) .long(OPT_FILE)
.takes_value(true)
.value_name("DATEFILE") .value_name("DATEFILE")
.value_hint(clap::ValueHint::FilePath) .value_hint(clap::ValueHint::FilePath)
.help("like --date; once for each line of DATEFILE"), .help("like --date; once for each line of DATEFILE"),
@ -284,7 +282,6 @@ pub fn uu_app<'a>() -> Command<'a> {
Arg::new(OPT_ISO_8601) Arg::new(OPT_ISO_8601)
.short('I') .short('I')
.long(OPT_ISO_8601) .long(OPT_ISO_8601)
.takes_value(true)
.value_name("FMT") .value_name("FMT")
.help(ISO_8601_HELP_STRING), .help(ISO_8601_HELP_STRING),
) )
@ -292,25 +289,25 @@ pub fn uu_app<'a>() -> Command<'a> {
Arg::new(OPT_RFC_EMAIL) Arg::new(OPT_RFC_EMAIL)
.short('R') .short('R')
.long(OPT_RFC_EMAIL) .long(OPT_RFC_EMAIL)
.help(RFC_5322_HELP_STRING), .help(RFC_5322_HELP_STRING)
.action(ArgAction::SetTrue),
) )
.arg( .arg(
Arg::new(OPT_RFC_3339) Arg::new(OPT_RFC_3339)
.long(OPT_RFC_3339) .long(OPT_RFC_3339)
.takes_value(true)
.value_name("FMT") .value_name("FMT")
.help(RFC_3339_HELP_STRING), .help(RFC_3339_HELP_STRING),
) )
.arg( .arg(
Arg::new(OPT_DEBUG) Arg::new(OPT_DEBUG)
.long(OPT_DEBUG) .long(OPT_DEBUG)
.help("annotate the parsed date, and warn about questionable usage to stderr"), .help("annotate the parsed date, and warn about questionable usage to stderr")
.action(ArgAction::SetTrue),
) )
.arg( .arg(
Arg::new(OPT_REFERENCE) Arg::new(OPT_REFERENCE)
.short('r') .short('r')
.long(OPT_REFERENCE) .long(OPT_REFERENCE)
.takes_value(true)
.value_name("FILE") .value_name("FILE")
.value_hint(clap::ValueHint::AnyPath) .value_hint(clap::ValueHint::AnyPath)
.help("display the last modification time of FILE"), .help("display the last modification time of FILE"),
@ -319,7 +316,6 @@ pub fn uu_app<'a>() -> Command<'a> {
Arg::new(OPT_SET) Arg::new(OPT_SET)
.short('s') .short('s')
.long(OPT_SET) .long(OPT_SET)
.takes_value(true)
.value_name("STRING") .value_name("STRING")
.help(OPT_SET_HELP_STRING), .help(OPT_SET_HELP_STRING),
) )
@ -328,9 +324,10 @@ pub fn uu_app<'a>() -> Command<'a> {
.short('u') .short('u')
.long(OPT_UNIVERSAL) .long(OPT_UNIVERSAL)
.alias(OPT_UNIVERSAL_2) .alias(OPT_UNIVERSAL_2)
.help("print or set Coordinated Universal Time (UTC)"), .help("print or set Coordinated Universal Time (UTC)")
.action(ArgAction::SetTrue),
) )
.arg(Arg::new(OPT_FORMAT).multiple_occurrences(false)) .arg(Arg::new(OPT_FORMAT))
} }
/// Return the appropriate format string for the given settings. /// Return the appropriate format string for the given settings.