1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
use std::{fmt::Display, process::Command};

pub mod app_installation;
pub mod file_transfer;
pub mod general;
pub mod networking;
pub mod scripting;
pub mod shell;

pub trait ADBCommand {
    /// Add mandatory parameters to the inner command and return it
    fn build(&mut self) -> Result<&mut Command, String>;

    /// Remove unnecessary or data that is already known from result
    fn process_output(&self, output: ADBResult) -> ADBResult;
}

pub trait ADBPathCommand {
    /// Set the path for the remote location
    fn path(&mut self, path: Option<String>);

    /// Add mandatory parameters to the inner command and return it
    fn build(&mut self) -> Result<&mut Command, String>;

    /// Remove unnecessary or data that is already known from result
    fn process_output(&self, output: ADBResult) -> ADBResult;
}

pub struct ADBResult {
    pub(crate) data: String,
}

impl ADBResult {
    pub fn to_vec(&self) -> Vec<String> {
        self.data.split("\r\n").map(|x| x.to_string()).collect()
    }
}

impl Display for ADBResult {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}", self.data)
    }
}