33// For the full copyright and license information, please view the LICENSE
44// file that was distributed with this source code.
55
6- // spell-checker:ignore getloadavg behaviour loadavg uptime upsecs updays upmins uphours boottime nusers utmpxname gettime clockid
6+ // spell-checker:ignore getloadavg behaviour loadavg uptime upsecs updays upmins uphours boottime nusers utmpxname gettime clockid couldnt
77
88use chrono:: { Local , TimeZone , Utc } ;
9+ use std:: collections:: HashMap ;
910#[ cfg( unix) ]
1011use std:: ffi:: OsString ;
1112use std:: io;
@@ -17,8 +18,8 @@ use uucore::uptime::*;
1718use clap:: { Arg , ArgAction , Command , ValueHint , builder:: ValueParser } ;
1819
1920use uucore:: format_usage;
20- use uucore:: locale:: get_message;
2121
22+ use uucore:: locale:: { get_message, get_message_with_args} ;
2223#[ cfg( unix) ]
2324#[ cfg( not( target_os = "openbsd" ) ) ]
2425use uucore:: utmpx:: * ;
@@ -31,11 +32,11 @@ pub mod options {
3132#[ derive( Debug , Error ) ]
3233pub enum UptimeError {
3334 // io::Error wrapper
34- #[ error( "couldn't get boot time: {0}" ) ]
35+ #[ error( "{}" , get_message_with_args ( "uptime-error-io" , HashMap :: from ( [ ( "error" . to_string ( ) , format! ( "{}" , . 0 ) ) ] ) ) ) ]
3536 IoErr ( #[ from] io:: Error ) ,
36- #[ error( "couldn't get boot time: Is a directory" ) ]
37+ #[ error( "{}" , get_message ( "uptime-error-target-is-dir" ) ) ]
3738 TargetIsDir ,
38- #[ error( "couldn't get boot time: Illegal seek" ) ]
39+ #[ error( "{}" , get_message ( "uptime-error-target-is-fifo" ) ) ]
3940 TargetIsFifo ,
4041}
4142
@@ -78,13 +79,13 @@ pub fn uu_app() -> Command {
7879 Arg :: new ( options:: SINCE )
7980 . short ( 's' )
8081 . long ( options:: SINCE )
81- . help ( "system up since")
82+ . help ( get_message ( "uptime-help- since") )
8283 . action ( ArgAction :: SetTrue ) ,
8384 ) ;
8485 #[ cfg( unix) ]
8586 cmd. arg (
8687 Arg :: new ( options:: PATH )
87- . help ( "file to search boot time from" )
88+ . help ( get_message ( "uptime-help-path" ) )
8889 . action ( ArgAction :: Set )
8990 . num_args ( 0 ..=1 )
9091 . value_parser ( ValueParser :: os_string ( ) )
@@ -130,9 +131,9 @@ fn uptime_with_file(file_path: &OsString) -> UResult<()> {
130131 let bytes = file_path. as_os_str ( ) . as_bytes ( ) ;
131132
132133 if bytes[ bytes. len ( ) - 1 ] != b'x' {
133- show_error ! ( "couldn't get boot time" ) ;
134+ show_error ! ( "{}" , get_message ( "uptime-error-couldnt- get- boot- time") ) ;
134135 print_time ( ) ;
135- print ! ( "up ???? days ??:??," ) ;
136+ print ! ( "{}" , get_message ( "uptime-output-unknown-uptime" ) ) ;
136137 print_nusers ( Some ( 0 ) ) ;
137138 print_loadavg ( ) ;
138139 set_exit_code ( 1 ) ;
@@ -142,7 +143,7 @@ fn uptime_with_file(file_path: &OsString) -> UResult<()> {
142143
143144 if non_fatal_error {
144145 print_time ( ) ;
145- print ! ( "up ???? days ??:??," ) ;
146+ print ! ( "{}" , get_message ( "uptime-output-unknown-uptime" ) ) ;
146147 print_nusers ( Some ( 0 ) ) ;
147148 print_loadavg ( ) ;
148149 return Ok ( ( ) ) ;
@@ -157,10 +158,10 @@ fn uptime_with_file(file_path: &OsString) -> UResult<()> {
157158 if let Some ( time) = boot_time {
158159 print_uptime ( Some ( time) ) ?;
159160 } else {
160- show_error ! ( "couldn't get boot time" ) ;
161+ show_error ! ( "{}" , get_message ( "uptime-error-couldnt- get- boot- time") ) ;
161162 set_exit_code ( 1 ) ;
162163
163- print ! ( "up ???? days ??:??," ) ;
164+ print ! ( "{}" , get_message ( "uptime-output-unknown-uptime" ) ) ;
164165 }
165166 user_count = count;
166167 }
@@ -171,10 +172,10 @@ fn uptime_with_file(file_path: &OsString) -> UResult<()> {
171172 if upsecs >= 0 {
172173 print_uptime ( Some ( upsecs) ) ?;
173174 } else {
174- show_error ! ( "couldn't get boot time" ) ;
175+ show_error ! ( "{}" , get_message ( "uptime-error-couldnt- get- boot- time") ) ;
175176 set_exit_code ( 1 ) ;
176177
177- print ! ( "up ???? days ??:??," ) ;
178+ print ! ( "{}" , get_message ( "uptime-output-unknown-uptime" ) ) ;
178179 }
179180 user_count = get_nusers ( file_path. to_str ( ) . expect ( "invalid utmp path file" ) ) ;
180181 }
0 commit comments