feat: autodetect an ADB device when no vendor or product ID is specified (#44)
* feat: autodetect an ADB device when no vendor or product ID is specified ### Changes - Added methods `autodetect` to `autodetect_with_custom_private_key` to `ADBUSBDevice` - Added private functions to check if a usb device has the signature of an ADB device - Made the `vendor_id` and `product_id` USB arguments optional and default to aforementioned methods * fix: improve github actions workflows --------- Co-authored-by: LIAUD Corentin <corentinliaud26@gmail.com>
This commit is contained in:
committed by
GitHub
parent
266265ca35
commit
cff0e68f46
@@ -13,10 +13,10 @@ fn parse_hex_id(id: &str) -> Result<u16, ParseIntError> {
|
||||
pub struct UsbCommand {
|
||||
/// Hexadecimal vendor id of this USB device
|
||||
#[clap(short = 'v', long = "vendor-id", value_parser=parse_hex_id, value_name="VID")]
|
||||
pub vendor_id: u16,
|
||||
pub vendor_id: Option<u16>,
|
||||
/// Hexadecimal product id of this USB device
|
||||
#[clap(short = 'p', long = "product-id", value_parser=parse_hex_id, value_name="PID")]
|
||||
pub product_id: u16,
|
||||
pub product_id: Option<u16>,
|
||||
/// Path to a custom private key to use for authentication
|
||||
#[clap(short = 'k', long = "private-key")]
|
||||
pub path_to_private_key: Option<PathBuf>,
|
||||
|
||||
@@ -158,11 +158,20 @@ fn main() -> Result<()> {
|
||||
}
|
||||
}
|
||||
Command::Usb(usb) => {
|
||||
let mut device = match usb.path_to_private_key {
|
||||
Some(pk) => {
|
||||
ADBUSBDevice::new_with_custom_private_key(usb.vendor_id, usb.product_id, pk)?
|
||||
let mut device = match (usb.vendor_id, usb.product_id) {
|
||||
(Some(vid), Some(pid)) => match usb.path_to_private_key {
|
||||
Some(pk) => ADBUSBDevice::new_with_custom_private_key(vid, pid, pk)?,
|
||||
None => ADBUSBDevice::new(vid, pid)?,
|
||||
},
|
||||
|
||||
(None, None) => match usb.path_to_private_key {
|
||||
Some(pk) => ADBUSBDevice::autodetect_with_custom_private_key(pk)?,
|
||||
None => ADBUSBDevice::autodetect()?,
|
||||
},
|
||||
|
||||
_ => {
|
||||
anyhow::bail!("please either supply values for both the --vendor-id and --product-id flags or none.");
|
||||
}
|
||||
None => ADBUSBDevice::new(usb.vendor_id, usb.product_id)?,
|
||||
};
|
||||
|
||||
match usb.commands {
|
||||
|
||||
Reference in New Issue
Block a user