@@ -134,13 +134,22 @@ impl From<InputDeckModeArg> for DeckStateMode {
134134 }
135135}
136136
137+ #[ derive( Debug ) ]
138+ pub struct LogLevel ( log:: LevelFilter ) ;
139+
140+ impl Default for LogLevel {
141+ fn default ( ) -> Self {
142+ LogLevel ( log:: LevelFilter :: Error )
143+ }
144+ }
145+
137146/// Shadows `clap_std::ClapCli` with extras for UEFI
138147///
139148/// The UEFI commandline currently doesn't use clap, so we need to shadow the struct.
140149/// Also it has extra options.
141- #[ derive( Debug ) ]
150+ #[ derive( Debug , Default ) ]
142151pub struct Cli {
143- pub verbosity : log :: LevelFilter ,
152+ pub verbosity : LogLevel ,
144153 pub versions : bool ,
145154 pub version : bool ,
146155 pub features : bool ,
@@ -212,9 +221,73 @@ pub struct Cli {
212221
213222pub fn parse ( args : & [ String ] ) -> Cli {
214223 #[ cfg( feature = "uefi" ) ]
215- return uefi:: parse ( args) ;
224+ let cli = uefi:: parse ( args) ;
216225 #[ cfg( not( feature = "uefi" ) ) ]
217- return clap_std:: parse ( args) ;
226+ let cli = clap_std:: parse ( args) ;
227+
228+ if cfg ! ( feature = "readonly" ) {
229+ // Initialize a new Cli with no arguments
230+ // Set all arguments that are readonly/safe
231+ // We explicitly only cope the safe ones so that if we add new arguments in the future,
232+ // which might be unsafe, we can't forget to exclude them from the safe set.
233+ // TODO: Instead of silently ignoring blocked command, we should remind the user
234+ Cli {
235+ verbosity : cli. verbosity ,
236+ versions : cli. versions ,
237+ version : cli. version ,
238+ esrt : cli. esrt ,
239+ device : cli. device ,
240+ power : cli. power ,
241+ thermal : cli. thermal ,
242+ sensors : cli. sensors ,
243+ // fansetduty
244+ // fansetrpm
245+ // autofanctrl
246+ privacy : cli. privacy ,
247+ pd_info : cli. version ,
248+ dp_hdmi_info : cli. dp_hdmi_info ,
249+ // dp_hdmi_update
250+ audio_card_info : cli. audio_card_info ,
251+ pd_bin : cli. pd_bin ,
252+ ec_bin : cli. ec_bin ,
253+ capsule : cli. capsule ,
254+ dump : cli. dump ,
255+ h2o_capsule : cli. h2o_capsule ,
256+ // dump_ec_flash
257+ // flash_ec
258+ // flash_ro_ec
259+ driver : cli. driver ,
260+ test : cli. test ,
261+ intrusion : cli. intrusion ,
262+ inputdeck : cli. inputdeck ,
263+ inputdeck_mode : cli. inputdeck_mode ,
264+ expansion_bay : cli. expansion_bay ,
265+ // charge_limit
266+ // charge_current_limit
267+ get_gpio : cli. get_gpio ,
268+ fp_led_level : cli. fp_led_level ,
269+ fp_brightness : cli. fp_brightness ,
270+ kblight : cli. kblight ,
271+ rgbkbd : cli. rgbkbd ,
272+ // tablet_mode
273+ // touchscreen_enable
274+ stylus_battery : cli. stylus_battery ,
275+ console : cli. console ,
276+ reboot_ec : cli. reboot_ec ,
277+ // ec_hib_delay
278+ hash : cli. hash ,
279+ pd_addrs : cli. pd_addrs ,
280+ pd_ports : cli. pd_ports ,
281+ help : cli. help ,
282+ info : cli. info ,
283+ // allupdate
284+ paginate : cli. paginate ,
285+ // raw_command
286+ ..Default :: default ( )
287+ }
288+ } else {
289+ cli
290+ }
218291}
219292
220293fn print_single_pd_details ( pd : & PdController ) {
@@ -815,7 +888,7 @@ fn compare_version(device: Option<HardwareDeviceType>, version: String, ec: &Cro
815888pub fn run_with_args ( args : & Cli , _allupdate : bool ) -> i32 {
816889 #[ cfg( feature = "uefi" ) ]
817890 {
818- log:: set_max_level ( args. verbosity ) ;
891+ log:: set_max_level ( args. verbosity . 0 ) ;
819892 }
820893 #[ cfg( not( feature = "uefi" ) ) ]
821894 {
@@ -824,7 +897,7 @@ pub fn run_with_args(args: &Cli, _allupdate: bool) -> i32 {
824897 // .filter("FRAMEWORK_COMPUTER_LOG")
825898 // .write_style("FRAMEWORK_COMPUTER_LOG_STYLE");
826899
827- let level = args. verbosity . as_str ( ) ;
900+ let level = args. verbosity . 0 . as_str ( ) ;
828901 env_logger:: Builder :: from_env ( env_logger:: Env :: default ( ) . default_filter_or ( level) )
829902 . format_target ( false )
830903 . format_timestamp ( None )
0 commit comments