Skip to content

Commit c6b12cf

Browse files
committed
uptime: remove path arg under Windows
1 parent b78f78b commit c6b12cf

File tree

1 file changed

+22
-24
lines changed

1 file changed

+22
-24
lines changed

src/uu/uptime/src/uptime.rs

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
use chrono::{Local, TimeZone, Utc};
99
use clap::ArgMatches;
10+
#[cfg(unix)]
11+
use std::ffi::OsString;
1012
use std::io;
1113
use thiserror::Error;
1214
use uucore::error::{UError, UResult};
@@ -60,25 +62,20 @@ impl UError for UptimeError {
6062
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
6163
let matches = uu_app().try_get_matches_from(args)?;
6264

63-
#[cfg(windows)]
64-
return default_uptime(&matches);
65-
6665
#[cfg(unix)]
67-
{
68-
use std::ffi::OsString;
69-
70-
let argument = matches.get_one::<OsString>(options::PATH);
66+
let file_path = matches.get_one::<OsString>(options::PATH);
67+
#[cfg(windows)]
68+
let file_path = None;
7169

72-
if let Some(file_path) = argument {
73-
uptime_with_file(file_path)
74-
} else {
75-
default_uptime(&matches)
76-
}
70+
if let Some(file_path) = file_path {
71+
uptime_with_file(file_path)
72+
} else {
73+
default_uptime(&matches)
7774
}
7875
}
7976

8077
pub fn uu_app() -> Command {
81-
Command::new(uucore::util_name())
78+
let cmd = Command::new(uucore::util_name())
8279
.version(uucore::crate_version!())
8380
.about(ABOUT)
8481
.override_usage(format_usage(USAGE))
@@ -89,19 +86,20 @@ pub fn uu_app() -> Command {
8986
.long(options::SINCE)
9087
.help("system up since")
9188
.action(ArgAction::SetTrue),
92-
)
93-
.arg(
94-
Arg::new(options::PATH)
95-
.help("file to search boot time from")
96-
.action(ArgAction::Set)
97-
.num_args(0..=1)
98-
.value_parser(ValueParser::os_string())
99-
.value_hint(ValueHint::AnyPath),
100-
)
89+
);
90+
#[cfg(unix)]
91+
cmd.arg(
92+
Arg::new(options::PATH)
93+
.help("file to search boot time from")
94+
.action(ArgAction::Set)
95+
.num_args(0..=1)
96+
.value_parser(ValueParser::os_string())
97+
.value_hint(ValueHint::AnyPath),
98+
)
10199
}
102100

103101
#[cfg(unix)]
104-
fn uptime_with_file(file_path: &std::ffi::OsString) -> UResult<()> {
102+
fn uptime_with_file(file_path: &OsString) -> UResult<()> {
105103
use std::fs;
106104
use std::os::unix::fs::FileTypeExt;
107105
use uucore::error::set_exit_code;
@@ -232,7 +230,7 @@ fn print_loadavg() {
232230

233231
#[cfg(unix)]
234232
#[cfg(not(target_os = "openbsd"))]
235-
fn process_utmpx(file: Option<&std::ffi::OsString>) -> (Option<time_t>, usize) {
233+
fn process_utmpx(file: Option<&OsString>) -> (Option<time_t>, usize) {
236234
let mut nusers = 0;
237235
let mut boot_time = None;
238236

0 commit comments

Comments
 (0)