1+ use crate :: efivar:: print_mode:: { Decimal , Verbose } ;
2+ use crate :: efivar:: types:: PrintMode ;
13use clap;
24use efivar;
35use ignore_result:: Ignore ;
@@ -118,16 +120,16 @@ fn list_variables(_parser_args: clap::ArgMatches) -> ExitCode {
118120 println ! ( "{}" , v) ;
119121 }
120122 return std:: process:: ExitCode :: from ( 0 ) ;
121- } ,
123+ }
122124 Err ( _) => {
123- let mut efivar_variables: efivar:: efivar:: EfiVariables = Default :: default ( ) ;
125+ let efivar_variables: efivar:: efivar:: EfiVariables = Default :: default ( ) ;
124126 match efivar_variables. list ( ) {
125127 Ok ( variables) => {
126128 for v in variables {
127129 println ! ( "{}" , v) ;
128130 }
129131 return std:: process:: ExitCode :: from ( 0 ) ;
130- } ,
132+ }
131133 Err ( e) => {
132134 eprintln ! ( "Failed to access EFI variables: {}" , e) ;
133135 return std:: process:: ExitCode :: from ( 1 ) ;
@@ -138,7 +140,40 @@ fn list_variables(_parser_args: clap::ArgMatches) -> ExitCode {
138140}
139141
140142fn print_variable ( parser_args : clap:: ArgMatches , print_mode : efivar:: types:: PrintMode ) -> ExitCode {
141- return std:: process:: ExitCode :: from ( 0 ) ;
143+ match parser_args. get_one :: < String > ( "name" ) {
144+ Some ( name) => {
145+ let efivar_fs_variables: efivar:: efivarfs:: EfiVariables = Default :: default ( ) ;
146+ match efivar_fs_variables. get_variable ( name) {
147+ Ok ( var) => {
148+ match print_mode {
149+ PrintMode :: VERBOSE => println ! ( "{}" , Verbose ( & var) ) ,
150+ PrintMode :: DECIMAL => println ! ( "{}" , Decimal ( & var) ) ,
151+ }
152+ return std:: process:: ExitCode :: from ( 0 ) ;
153+ }
154+ Err ( _) => {
155+ let efivar_variables: efivar:: efivar:: EfiVariables = Default :: default ( ) ;
156+ match efivar_variables. get_variable ( name) {
157+ Ok ( var) => {
158+ match print_mode {
159+ PrintMode :: VERBOSE => println ! ( "{}" , Verbose ( & var) ) ,
160+ PrintMode :: DECIMAL => println ! ( "{}" , Decimal ( & var) ) ,
161+ }
162+ return std:: process:: ExitCode :: from ( 0 ) ;
163+ }
164+ Err ( e) => {
165+ eprintln ! ( "Failed to read variable: {}" , e) ;
166+ return std:: process:: ExitCode :: from ( 1 ) ;
167+ }
168+ }
169+ }
170+ } ;
171+ }
172+ None => {
173+ eprintln ! ( "No variable name given" ) ;
174+ return std:: process:: ExitCode :: from ( 1 ) ;
175+ }
176+ } ;
142177}
143178
144179fn append_attributes ( parser_args : clap:: ArgMatches ) -> ExitCode {
@@ -193,7 +228,11 @@ fn main() -> ExitCode {
193228 } else if matches. get_one :: < & str > ( "export" ) . is_some ( ) {
194229 return export_variable ( matches) ;
195230 } else {
196- parser. write_help ( & mut io:: stderr ( ) ) . ignore ( ) ;
197- return std:: process:: ExitCode :: from ( 1 ) ;
231+ if matches. get_one :: < String > ( "name" ) . is_some ( ) {
232+ return print_variable ( matches, efivar:: types:: PrintMode :: VERBOSE ) ;
233+ } else {
234+ parser. write_help ( & mut io:: stderr ( ) ) . ignore ( ) ;
235+ return std:: process:: ExitCode :: from ( 1 ) ;
236+ }
198237 }
199238}
0 commit comments