use std::{fmt::Display, process::Command};
use crate::{ADBCommand, ADBResult};
use super::CompressionAlgorithm;
pub struct ADBSync {
location: SyncLocation,
shell: Command,
}
impl ADBSync {
pub fn new(location: SyncLocation) -> Self {
let mut cmd = Command::new("adb");
cmd.arg("sync");
ADBSync {
shell: cmd,
location,
}
}
pub fn dry_run(mut self) -> Self {
self.shell.arg("-n");
self
}
pub fn list(mut self) -> Self {
self.shell.arg("-l");
self
}
pub fn compression(mut self, algorithm: CompressionAlgorithm) -> Self {
self.shell.arg("-z").arg(algorithm.to_string());
self
}
pub fn no_compression(mut self) -> Self {
self.shell.arg("-Z");
self
}
}
impl ADBCommand for ADBSync {
fn build(&mut self) -> Result<&mut Command, String> {
self.shell.arg(self.location.to_string());
Ok(&mut self.shell)
}
fn process_output(&self, output: ADBResult) -> ADBResult {
output
}
}
pub enum SyncLocation {
All,
Data,
Odm,
Oem,
Product,
System,
SystemExt,
Vendor,
}
impl Display for SyncLocation {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"{}",
match self {
SyncLocation::All => "all",
SyncLocation::Data => "data",
SyncLocation::Odm => "odm",
SyncLocation::Oem => "oem",
SyncLocation::Product => "product",
SyncLocation::System => "system",
SyncLocation::SystemExt => "system_ext",
SyncLocation::Vendor => "vendor",
}
)
}
}