1use argh::{FromArgValue, FromArgs};
6
7#[derive(Debug, PartialEq)]
8pub struct UsbDevice {
9 pub vendor_id: u16,
10 pub product_id: Option<u16>,
11}
12
13impl FromArgValue for UsbDevice {
14 fn from_arg_value(value: &str) -> Result<Self, String> {
15 if let Some((vid, pid)) = value.split_once(':') {
16 let vid = u16::from_str_radix(vid, 16)
17 .map_err(|_| "Vendor ID is not a valid hexadecimal number'.".to_string())?;
18
19 let pid = u16::from_str_radix(pid, 16)
20 .map_err(|_| "Product ID is not a valid hexadecimal number'.".to_string())?;
21
22 Ok(UsbDevice { vendor_id: vid, product_id: Some(pid) })
23 } else {
24 let vid = u16::from_str_radix(value, 16)
25 .map_err(|_| "Vendor id is not a valid hexadecimal number'.".to_string())?;
26
27 Ok(UsbDevice { vendor_id: vid, product_id: None })
28 }
29 }
30}
31
32#[derive(FromArgs, Debug, PartialEq)]
33pub struct Args {
35 #[argh(switch, short = 't')]
36 pub tree: bool,
38 #[argh(switch, short = 'v')]
39 pub verbose: bool,
41 #[argh(option, short = 'c')]
42 pub configuration: Option<u8>,
45 #[argh(option, short = 'd')]
46 pub device: Option<UsbDevice>,
49}