@@ -26,29 +26,42 @@ fn display(uname: &UNameOutput) -> String {
2626
2727impl ShellCommand for UnameCommand {
2828 fn execute ( & self , mut context : ShellCommandContext ) -> LocalBoxFuture < ' static , ExecuteResult > {
29- let matches = uu_uname:: uu_app ( )
30- . no_binary_name ( true )
31- . try_get_matches_from ( context. args )
32- . unwrap ( ) ;
29+ Box :: pin ( async move {
30+ match execute_uname ( & mut context) {
31+ Ok ( _) => ExecuteResult :: from_exit_code ( 0 ) ,
32+ Err ( e) => {
33+ context. stderr . write_line ( & e) . ok ( ) ;
34+ ExecuteResult :: from_exit_code ( 1 )
35+ }
36+ }
37+ } )
38+ }
39+ }
3340
34- let options = uu_uname:: Options {
35- all : matches. get_flag ( options:: ALL ) ,
36- kernel_name : matches. get_flag ( options:: KERNEL_NAME ) ,
37- nodename : matches. get_flag ( options:: NODENAME ) ,
38- kernel_release : matches. get_flag ( options:: KERNEL_RELEASE ) ,
39- kernel_version : matches. get_flag ( options:: KERNEL_VERSION ) ,
40- machine : matches. get_flag ( options:: MACHINE ) ,
41- processor : matches. get_flag ( options:: PROCESSOR ) ,
42- hardware_platform : matches. get_flag ( options:: HARDWARE_PLATFORM ) ,
43- os : matches. get_flag ( options:: OS ) ,
44- } ;
41+ fn execute_uname ( context : & mut ShellCommandContext ) -> Result < ( ) , String > {
42+ let matches = uu_uname:: uu_app ( )
43+ . override_usage ( "uname [OPTION]..." )
44+ . no_binary_name ( true )
45+ . try_get_matches_from ( & context. args )
46+ . map_err ( |e| e. to_string ( ) ) ?;
4547
46- let uname = UNameOutput :: new ( & options) . unwrap ( ) ;
47- context
48- . stdout
49- . write_line ( display ( & uname) . trim_end ( ) )
50- . unwrap ( ) ;
48+ let options = uu_uname:: Options {
49+ all : matches. get_flag ( options:: ALL ) ,
50+ kernel_name : matches. get_flag ( options:: KERNEL_NAME ) ,
51+ nodename : matches. get_flag ( options:: NODENAME ) ,
52+ kernel_release : matches. get_flag ( options:: KERNEL_RELEASE ) ,
53+ kernel_version : matches. get_flag ( options:: KERNEL_VERSION ) ,
54+ machine : matches. get_flag ( options:: MACHINE ) ,
55+ processor : matches. get_flag ( options:: PROCESSOR ) ,
56+ hardware_platform : matches. get_flag ( options:: HARDWARE_PLATFORM ) ,
57+ os : matches. get_flag ( options:: OS ) ,
58+ } ;
5159
52- Box :: pin ( futures:: future:: ready ( ExecuteResult :: from_exit_code ( 0 ) ) )
53- }
60+ let uname = UNameOutput :: new ( & options) . unwrap ( ) ;
61+ context
62+ . stdout
63+ . write_line ( display ( & uname) . trim_end ( ) )
64+ . map_err ( |e| e. to_string ( ) ) ?;
65+
66+ Ok ( ( ) )
5467}
0 commit comments