android_tools_rs/aapt2/
daemon.rs

1use crate::error::*;
2use std::{
3    path::{Path, PathBuf},
4    process::Command,
5};
6
7pub struct Aapt2Daemon {
8    trace_folder: PathBuf,
9    help: bool,
10}
11
12impl Aapt2Daemon {
13    /// Initialize struct Aapt2Daemon and then specifies trace folder
14    pub fn new(trace_folder: &Path) -> Self {
15        Self {
16            trace_folder: trace_folder.to_owned(),
17            help: false,
18        }
19    }
20
21    /// Displays this help menu
22    pub fn help(&mut self, help: bool) -> &mut Self {
23        self.help = help;
24        self
25    }
26
27    /// Opens the command line and launches aapt2 daemon with arguments
28    pub fn run(&self) -> Result<()> {
29        let mut aapt2 = Command::new("aapt2");
30        aapt2.arg("daemon");
31        aapt2.arg(&self.trace_folder);
32        if self.help {
33            aapt2.arg("-h");
34        }
35        aapt2.output_err(true)?;
36        Ok(())
37    }
38}