7
7
8
8
use chrono:: { Local , TimeZone , Utc } ;
9
9
use clap:: ArgMatches ;
10
+ #[ cfg( unix) ]
11
+ use std:: ffi:: OsString ;
10
12
use std:: io;
11
13
use thiserror:: Error ;
12
14
use uucore:: error:: { UError , UResult } ;
@@ -60,25 +62,20 @@ impl UError for UptimeError {
60
62
pub fn uumain ( args : impl uucore:: Args ) -> UResult < ( ) > {
61
63
let matches = uu_app ( ) . try_get_matches_from ( args) ?;
62
64
63
- #[ cfg( windows) ]
64
- return default_uptime ( & matches) ;
65
-
66
65
#[ 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 ;
71
69
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)
77
74
}
78
75
}
79
76
80
77
pub fn uu_app ( ) -> Command {
81
- Command :: new ( uucore:: util_name ( ) )
78
+ let cmd = Command :: new ( uucore:: util_name ( ) )
82
79
. version ( uucore:: crate_version!( ) )
83
80
. about ( ABOUT )
84
81
. override_usage ( format_usage ( USAGE ) )
@@ -89,19 +86,20 @@ pub fn uu_app() -> Command {
89
86
. long ( options:: SINCE )
90
87
. help ( "system up since" )
91
88
. 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
+ )
101
99
}
102
100
103
101
#[ cfg( unix) ]
104
- fn uptime_with_file ( file_path : & std :: ffi :: OsString ) -> UResult < ( ) > {
102
+ fn uptime_with_file ( file_path : & OsString ) -> UResult < ( ) > {
105
103
use std:: fs;
106
104
use std:: os:: unix:: fs:: FileTypeExt ;
107
105
use uucore:: error:: set_exit_code;
@@ -232,7 +230,7 @@ fn print_loadavg() {
232
230
233
231
#[ cfg( unix) ]
234
232
#[ 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 ) {
236
234
let mut nusers = 0 ;
237
235
let mut boot_time = None ;
238
236
0 commit comments