use abscissa::Callable;
use std::process;
use yubihsm::connector::usb::Devices;
#[derive(Debug, Default, Options)]
pub struct DetectCommand {
#[options(short = "c", long = "config")]
pub config: Option<String>,
#[options(short = "v", long = "verbose")]
pub verbose: bool,
}
impl Callable for DetectCommand {
fn call(&self) {
let devices = Devices::new(Default::default()).unwrap_or_else(|e| {
status_err!("couldn't detect USB devices: {}", e);
process::exit(1);
});
if devices.is_empty() {
status_err!("no YubiHSM2 devices detected!");
process::exit(1);
}
println!("Detected YubiHSM2 USB devices:");
for device in devices.iter() {
println!(
"- Serial #{} (bus {})",
device.serial_number.as_str(),
device.bus_number(),
);
}
}
}