use crate::error::*;
use std::path::{Path, PathBuf};
use std::process::Command;
#[derive(Debug, Default)]
pub struct InstallApks {
apks: PathBuf,
local_testing: bool,
device_id: Option<String>,
}
impl InstallApks {
pub fn new(apks: &Path) -> Self {
Self {
apks: apks.to_owned(),
..Default::default()
}
}
pub fn local_testing(&mut self, local_testing: bool) -> &mut Self {
self.local_testing = local_testing;
self
}
pub fn device_id(&mut self, device_id: String) -> &mut Self {
self.device_id = Some(device_id);
self
}
pub fn run(&self) -> Result<()> {
let mut install_apks = Command::new("java");
install_apks.arg("-jar");
if let Ok(bundletool_path) = std::env::var("BUNDLETOOL_PATH") {
install_apks.arg(bundletool_path);
} else {
return Err(Error::BundletoolNotFound);
}
install_apks.arg("install-apks");
install_apks.arg("--apks");
install_apks.arg(&self.apks);
if self.local_testing {
install_apks.arg("--local-testing");
}
if let Some(device_id) = &self.device_id {
install_apks.arg("--device-id").arg(device_id);
}
install_apks.output_err(true)?;
Ok(())
}
}