Debian Codegraph @

examples/systemd-hwdb.rs

raw symbols SCIP
1 use std::env;
2 use std::process;
3 use udevrs::{udev_new, UdevHwdb};
4
5 /// Simple program to query the systemd hwdb like `systemd-hwdb`
6 fn main() {
7 env_logger::init();
8 let args: Vec<String> = env::args().collect();
9
10 if args.len() != 2 {
11 eprintln!("Usage: {} <hwdb_key>", args[0]);
12 process::exit(1);
13 }
14
15 let key = &args[1];
16
17 // Initialize the Hwdb
18 let mut hwdb = match UdevHwdb::new(udev_new()) {
19 Ok(db) => db,
20 Err(e) => {
21 eprintln!("Failed to initialize hwdb: {}", e);
22 process::exit(1);
23 }
24 };
25
26 // Query the hwdb with the provided key
27 log::info!("Querying hwdb with key: {}", key);
28 if let Some(properties) = hwdb.query(key) {
29 properties
30 .iter()
31 .for_each(|e| println!("{}: {}", e.name(), e.value()));
32 };
33 }