1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

uptime: remove path arg under Windows

This commit is contained in:
Daniel Hofstetter 2025-05-06 16:47:52 +02:00
parent b78f78bedf
commit c6b12cfb96

View file

@ -7,6 +7,8 @@
use chrono::{Local, TimeZone, Utc}; use chrono::{Local, TimeZone, Utc};
use clap::ArgMatches; use clap::ArgMatches;
#[cfg(unix)]
use std::ffi::OsString;
use std::io; use std::io;
use thiserror::Error; use thiserror::Error;
use uucore::error::{UError, UResult}; use uucore::error::{UError, UResult};
@ -60,25 +62,20 @@ impl UError for UptimeError {
pub fn uumain(args: impl uucore::Args) -> UResult<()> { pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().try_get_matches_from(args)?; let matches = uu_app().try_get_matches_from(args)?;
#[cfg(windows)]
return default_uptime(&matches);
#[cfg(unix)] #[cfg(unix)]
{ let file_path = matches.get_one::<OsString>(options::PATH);
use std::ffi::OsString; #[cfg(windows)]
let file_path = None;
let argument = matches.get_one::<OsString>(options::PATH); if let Some(file_path) = file_path {
uptime_with_file(file_path)
if let Some(file_path) = argument { } else {
uptime_with_file(file_path) default_uptime(&matches)
} else {
default_uptime(&matches)
}
} }
} }
pub fn uu_app() -> Command { pub fn uu_app() -> Command {
Command::new(uucore::util_name()) let cmd = Command::new(uucore::util_name())
.version(uucore::crate_version!()) .version(uucore::crate_version!())
.about(ABOUT) .about(ABOUT)
.override_usage(format_usage(USAGE)) .override_usage(format_usage(USAGE))
@ -89,19 +86,20 @@ pub fn uu_app() -> Command {
.long(options::SINCE) .long(options::SINCE)
.help("system up since") .help("system up since")
.action(ArgAction::SetTrue), .action(ArgAction::SetTrue),
) );
.arg( #[cfg(unix)]
Arg::new(options::PATH) cmd.arg(
.help("file to search boot time from") Arg::new(options::PATH)
.action(ArgAction::Set) .help("file to search boot time from")
.num_args(0..=1) .action(ArgAction::Set)
.value_parser(ValueParser::os_string()) .num_args(0..=1)
.value_hint(ValueHint::AnyPath), .value_parser(ValueParser::os_string())
) .value_hint(ValueHint::AnyPath),
)
} }
#[cfg(unix)] #[cfg(unix)]
fn uptime_with_file(file_path: &std::ffi::OsString) -> UResult<()> { fn uptime_with_file(file_path: &OsString) -> UResult<()> {
use std::fs; use std::fs;
use std::os::unix::fs::FileTypeExt; use std::os::unix::fs::FileTypeExt;
use uucore::error::set_exit_code; use uucore::error::set_exit_code;
@ -232,7 +230,7 @@ fn print_loadavg() {
#[cfg(unix)] #[cfg(unix)]
#[cfg(not(target_os = "openbsd"))] #[cfg(not(target_os = "openbsd"))]
fn process_utmpx(file: Option<&std::ffi::OsString>) -> (Option<time_t>, usize) { fn process_utmpx(file: Option<&OsString>) -> (Option<time_t>, usize) {
let mut nusers = 0; let mut nusers = 0;
let mut boot_time = None; let mut boot_time = None;