use crate::error::*;
use std::path::{Path, PathBuf};
use std::process::Command;
pub struct GetSizeTotal {
apks: PathBuf,
device_spec: Option<PathBuf>,
dimensions: Option<String>,
instant: bool,
modules: Option<String>,
}
impl GetSizeTotal {
pub fn new(apks: &Path) -> Self {
Self {
apks: apks.to_owned(),
device_spec: None,
dimensions: None,
instant: false,
modules: None,
}
}
pub fn device_spec(&mut self, device_spec: &Path) -> &mut Self {
self.device_spec = Some(device_spec.to_owned());
self
}
pub fn dimensions(&mut self, dimensions: String) -> &mut Self {
self.dimensions = Some(dimensions);
self
}
pub fn instant(&mut self, instant: bool) -> &mut Self {
self.instant = instant;
self
}
pub fn modules(&mut self, modules: String) -> &mut Self {
self.modules = Some(modules);
self
}
pub fn run(&self) -> Result<()> {
let mut get_size_total = Command::new("java");
get_size_total.arg("-jar");
if let Ok(bundletool_path) = std::env::var("BUNDLETOOL_PATH") {
get_size_total.arg(bundletool_path);
} else {
return Err(Error::BundletoolNotFound);
}
get_size_total.arg("get-size");
get_size_total.arg("total");
get_size_total.arg("--apks");
get_size_total.arg(&self.apks);
if let Some(device_spec) = &self.device_spec {
get_size_total.arg("--device-spec").arg(device_spec);
}
if let Some(dimensions) = &self.dimensions {
get_size_total.arg("--dimensions").arg(dimensions);
}
if self.instant {
get_size_total.arg("--instant");
}
if let Some(modules) = &self.modules {
get_size_total.arg("--modules").arg(modules);
}
get_size_total.output_err(true)?;
Ok(())
}
}