From 9508bd8aa8336b94efb5d2069aa8c79c3fe8b171 Mon Sep 17 00:00:00 2001 From: Rudxain <76864299+Rudxain@users.noreply.github.com> Date: Mon, 10 Mar 2025 11:50:34 -0400 Subject: [PATCH] chore(ADB): add `version` method to internal ADB API --- src/core/adb.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/core/adb.rs b/src/core/adb.rs index 9cc6c7d..6f70a3a 100644 --- a/src/core/adb.rs +++ b/src/core/adb.rs @@ -63,12 +63,15 @@ pub fn to_trimmed_utf8(v: Vec) -> String { pub struct ACommand(std::process::Command); impl ACommand { /// `adb` command builder + #[must_use] pub fn new() -> Self { Self(std::process::Command::new("adb")) } + /// `shell` sub-command builder. /// /// If `device_serial` is empty, it lets ADB choose the default device. + #[must_use] pub fn shell>(mut self, device_serial: S) -> ShellCommand { let serial = device_serial.as_ref(); if !serial.is_empty() { @@ -77,6 +80,7 @@ impl ACommand { self.0.arg("shell"); ShellCommand(self) } + /// Header-less list of attached devices (as serials) and their statuses: /// - USB /// - TCP/IP: WIFI, Ethernet, etc... @@ -107,6 +111,15 @@ impl ACommand { }) .collect()) } + + /// `version` sub-command, splitted by lines + pub fn version(mut self) -> Result, String> { + self.0.arg("version"); + // typically 5 allocs (after `lines`). + // ideally 0, if we didn't use `lines`. + Ok(self.run()?.lines().map(str::to_string).collect()) + } + /// General executor fn run(self) -> Result { let mut cmd = self.0;