From e4aad6d971ae79f84504f98809154801e5d25530 Mon Sep 17 00:00:00 2001 From: 353fc443 <353fc443@pm.me> Date: Thu, 9 Sep 2021 17:59:02 +0000 Subject: [PATCH] uptime: added UResult --- src/uu/uptime/src/uptime.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/uu/uptime/src/uptime.rs b/src/uu/uptime/src/uptime.rs index e58f398db..f649b96b6 100644 --- a/src/uu/uptime/src/uptime.rs +++ b/src/uu/uptime/src/uptime.rs @@ -17,6 +17,8 @@ extern crate uucore; pub use uucore::libc; use uucore::libc::time_t; +use uucore::error::{UResult, USimpleError}; + static ABOUT: &str = "Display the current time, the length of time the system has been up,\n\ the number of users on the system, and the average number of jobs\n\ in the run queue over the last 1, 5 and 15 minutes."; @@ -36,21 +38,20 @@ fn usage() -> String { format!("{0} [OPTION]...", uucore::execution_phrase()) } -pub fn uumain(args: impl uucore::Args) -> i32 { +#[uucore_procs::gen_uumain] +pub fn uumain(args: impl uucore::Args) -> UResult<()> { let usage = usage(); let matches = uu_app().usage(&usage[..]).get_matches_from(args); let (boot_time, user_count) = process_utmpx(); let uptime = get_uptime(boot_time); if uptime < 0 { - show_error!("could not retrieve system uptime"); - - 1 + Err(USimpleError::new(1, "could not retrieve system uptime")) } else { if matches.is_present(options::SINCE) { let initial_date = Local.timestamp(Utc::now().timestamp() - uptime, 0); println!("{}", initial_date.format("%Y-%m-%d %H:%M:%S")); - return 0; + return Ok(()); } print_time(); @@ -59,7 +60,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { print_nusers(user_count); print_loadavg(); - 0 + Ok(()) } }