uptime: update to clap 4

This commit is contained in:
Terts Diepraam 2022-10-01 12:00:41 +02:00
parent 12048cda68
commit e99969b678
2 changed files with 6 additions and 5 deletions

View file

@ -16,7 +16,7 @@ path = "src/uptime.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", features=["libc", "utmpx"] } uucore = { version=">=0.0.16", package="uucore", path="../../uucore", features=["libc", "utmpx"] }
[[bin]] [[bin]]

View file

@ -9,7 +9,7 @@
// spell-checker:ignore (ToDO) getloadavg upsecs updays nusers loadavg boottime uphours upmins // spell-checker:ignore (ToDO) getloadavg upsecs updays nusers loadavg boottime uphours upmins
use chrono::{Local, TimeZone, Utc}; use chrono::{Local, TimeZone, Utc};
use clap::{crate_version, Arg, Command}; use clap::{crate_version, Arg, ArgAction, Command};
use uucore::format_usage; use uucore::format_usage;
// import crate time from utmpx // import crate time from utmpx
@ -43,7 +43,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
if uptime < 0 { if uptime < 0 {
Err(USimpleError::new(1, "could not retrieve system uptime")) Err(USimpleError::new(1, "could not retrieve system uptime"))
} else { } else {
if matches.contains_id(options::SINCE) { if matches.get_flag(options::SINCE) {
let initial_date = Local.timestamp(Utc::now().timestamp() - uptime, 0); let initial_date = Local.timestamp(Utc::now().timestamp() - uptime, 0);
println!("{}", initial_date.format("%Y-%m-%d %H:%M:%S")); println!("{}", initial_date.format("%Y-%m-%d %H:%M:%S"));
return Ok(()); return Ok(());
@ -59,7 +59,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
} }
} }
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)
@ -69,7 +69,8 @@ pub fn uu_app<'a>() -> Command<'a> {
Arg::new(options::SINCE) Arg::new(options::SINCE)
.short('s') .short('s')
.long(options::SINCE) .long(options::SINCE)
.help("system up since"), .help("system up since")
.action(ArgAction::SetTrue),
) )
} }