@@ -148,36 +148,47 @@ struct DeviceDumper {}
148148#[ async_trait]
149149impl Dumper for DeviceDumper {
150150 async fn dump ( & self , state : & State ) -> Result < ( ) , ModuleError > {
151- let inf_regex = Regex :: new ( r"^oem[0-9]+\.inf$" ) . unwrap ( ) ;
152- let devices: Vec < Device > = enumerate_devices ( )
153- . into_module_report ( DEVICE_MODULE_NAME ) ?
154- . into_iter ( )
155- . filter ( |d| inf_regex. is_match ( d. inf_name ( ) . unwrap_or ( "" ) ) )
156- . filter ( is_of_interest)
157- . collect ( ) ;
158-
159- let file_path =
160- get_path_to_dump ( state, "devices.json" ) . into_module_report ( DEVICE_MODULE_NAME ) ?;
161- let dump_file = create_dump_file ( & file_path) . into_module_report ( DEVICE_MODULE_NAME ) ?;
162- let file_name = file_path. as_path ( ) . to_str ( ) . unwrap ( ) ;
163-
164- if devices. is_empty ( ) {
165- println ! ( "No devices to dump" ) ;
166- return Ok ( ( ) ) ;
167- }
151+ dump_filtered ( state, "devices.json" , is_of_interest) . await
152+ }
168153
169- serde_json :: to_writer_pretty ( dump_file , & devices )
170- . into_report ( )
171- . attach_printable_lazy ( || format ! ( "failed to dump devices into '{}'" , file_name ) )
172- . into_module_report ( DEVICE_MODULE_NAME ) ? ;
154+ async fn dumpall ( & self , state : & State ) -> Result < ( ) , ModuleError > {
155+ dump_filtered ( state , "devices-all.json" , |_| true ) . await
156+ }
157+ }
173158
174- match devices. len ( ) {
175- 1 => println ! ( "Dumped 1 device to {}" , file_name) ,
176- n => println ! ( "Dumped {} devices to {}" , n, file_name) ,
177- }
159+ async fn dump_filtered < F : Fn ( & Device ) -> bool > (
160+ state : & State ,
161+ output_file : & str ,
162+ filter_fn : F ,
163+ ) -> Result < ( ) , ModuleError > {
164+ let inf_regex = Regex :: new ( r"^oem[0-9]+\.inf$" ) . unwrap ( ) ;
165+ let devices: Vec < Device > = enumerate_devices ( )
166+ . into_module_report ( DEVICE_MODULE_NAME ) ?
167+ . into_iter ( )
168+ . filter ( |d| inf_regex. is_match ( d. inf_name ( ) . unwrap_or ( "" ) ) )
169+ . filter ( filter_fn)
170+ . collect ( ) ;
171+
172+ let file_path = get_path_to_dump ( state, output_file) . into_module_report ( DEVICE_MODULE_NAME ) ?;
173+ let dump_file = create_dump_file ( & file_path) . into_module_report ( DEVICE_MODULE_NAME ) ?;
174+ let file_name = file_path. as_path ( ) . to_str ( ) . unwrap ( ) ;
175+
176+ if devices. is_empty ( ) {
177+ println ! ( "No devices to dump" ) ;
178+ return Ok ( ( ) ) ;
179+ }
178180
179- Ok ( ( ) )
181+ serde_json:: to_writer_pretty ( dump_file, & devices)
182+ . into_report ( )
183+ . attach_printable_lazy ( || format ! ( "failed to dump devices into '{}'" , file_name) )
184+ . into_module_report ( DEVICE_MODULE_NAME ) ?;
185+
186+ match devices. len ( ) {
187+ 1 => println ! ( "Dumped 1 device to {}" , file_name) ,
188+ n => println ! ( "Dumped {} devices to {}" , n, file_name) ,
180189 }
190+
191+ Ok ( ( ) )
181192}
182193
183194#[ derive( Deserialize , Debug ) ]
0 commit comments