@@ -44,14 +44,10 @@ pub enum UptimeError {
44
44
// io::Error wrapper
45
45
#[ error( "couldn't get boot time: {0}" ) ]
46
46
IoErr ( #[ from] io:: Error ) ,
47
-
48
47
#[ error( "couldn't get boot time: Is a directory" ) ]
49
48
TargetIsDir ,
50
-
51
49
#[ error( "couldn't get boot time: Illegal seek" ) ]
52
50
TargetIsFifo ,
53
- #[ error( "extra operand '{0}'" ) ]
54
- ExtraOperandError ( String ) ,
55
51
}
56
52
57
53
impl UError for UptimeError {
@@ -70,30 +66,14 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
70
66
#[ cfg( unix) ]
71
67
{
72
68
use std:: ffi:: OsString ;
73
- use uucore:: error:: set_exit_code;
74
- use uucore:: show_error;
75
69
76
- let argument = matches. get_many :: < OsString > ( options:: PATH ) ;
70
+ let argument = matches. get_one :: < OsString > ( options:: PATH ) ;
77
71
78
- // Switches to default uptime behaviour if there is no argument
79
- if argument. is_none ( ) {
80
- return default_uptime ( & matches) ;
81
- }
82
- let mut arg_iter = argument. unwrap ( ) ;
83
-
84
- let file_path = arg_iter. next ( ) . unwrap ( ) ;
85
- if let Some ( path) = arg_iter. next ( ) {
86
- // Uptime doesn't attempt to calculate boot time if there is extra arguments.
87
- // Its a fatal error
88
- show_error ! (
89
- "{}" ,
90
- UptimeError :: ExtraOperandError ( path. to_owned( ) . into_string( ) . unwrap( ) )
91
- ) ;
92
- set_exit_code ( 1 ) ;
93
- return Ok ( ( ) ) ;
72
+ if let Some ( file_path) = argument {
73
+ uptime_with_file ( file_path)
74
+ } else {
75
+ default_uptime ( & matches)
94
76
}
95
-
96
- uptime_with_file ( file_path)
97
77
}
98
78
}
99
79
@@ -113,7 +93,8 @@ pub fn uu_app() -> Command {
113
93
. arg (
114
94
Arg :: new ( options:: PATH )
115
95
. help ( "file to search boot time from" )
116
- . action ( ArgAction :: Append )
96
+ . action ( ArgAction :: Set )
97
+ . num_args ( 0 ..=1 )
117
98
. value_parser ( ValueParser :: os_string ( ) )
118
99
. value_hint ( ValueHint :: AnyPath ) ,
119
100
)
0 commit comments