adb_utils/commands/
mod.rs

1use std::{fmt::Display, process::Command};
2
3pub mod app_installation;
4pub mod file_transfer;
5pub mod general;
6pub mod networking;
7pub mod scripting;
8pub mod shell;
9
10pub trait ADBCommand {
11    /// Add mandatory parameters to the inner command and return it
12    fn build(&mut self) -> Result<&mut Command, String>;
13
14    /// Remove unnecessary or data that is already known from result
15    fn process_output(&self, output: ADBResult) -> ADBResult;
16}
17
18pub trait ADBPathCommand {
19    /// Set the path for the remote location
20    fn path(&mut self, path: Option<String>);
21
22    /// Add mandatory parameters to the inner command and return it
23    fn build(&mut self) -> Result<&mut Command, String>;
24
25    /// Remove unnecessary or data that is already known from result
26    fn process_output(&self, output: ADBResult) -> ADBResult;
27}
28
29pub struct ADBResult {
30    pub(crate) data: String,
31}
32
33impl ADBResult {
34    pub fn to_vec(&self) -> Vec<String> {
35        self.data.split("\r\n").map(|x| x.to_string()).collect()
36    }
37}
38
39impl Display for ADBResult {
40    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
41        write!(f, "{}", self.data)
42    }
43}