hdc_rs/
app.rs

1//! Application management functionality
2
3/// Application install options
4#[derive(Debug, Clone, Default)]
5pub struct InstallOptions {
6    /// Replace existing application
7    pub replace: bool,
8    /// Install shared bundle for multi-apps
9    pub shared: bool,
10}
11
12impl InstallOptions {
13    /// Create default install options
14    pub fn new() -> Self {
15        Self::default()
16    }
17
18    /// Set replace option
19    pub fn replace(mut self, replace: bool) -> Self {
20        self.replace = replace;
21        self
22    }
23
24    /// Set shared option
25    pub fn shared(mut self, shared: bool) -> Self {
26        self.shared = shared;
27        self
28    }
29
30    /// Convert to command line flags
31    pub fn to_flags(&self) -> String {
32        let mut flags = Vec::new();
33        if self.replace {
34            flags.push("-r");
35        }
36        if self.shared {
37            flags.push("-s");
38        }
39        flags.join(" ")
40    }
41}
42
43/// Application uninstall options
44#[derive(Debug, Clone, Default)]
45pub struct UninstallOptions {
46    /// Keep the data and cache directories
47    pub keep_data: bool,
48    /// Remove shared bundle
49    pub shared: bool,
50}
51
52impl UninstallOptions {
53    /// Create default uninstall options
54    pub fn new() -> Self {
55        Self::default()
56    }
57
58    /// Set keep_data option
59    pub fn keep_data(mut self, keep: bool) -> Self {
60        self.keep_data = keep;
61        self
62    }
63
64    /// Set shared option
65    pub fn shared(mut self, shared: bool) -> Self {
66        self.shared = shared;
67        self
68    }
69
70    /// Convert to command line flags
71    pub fn to_flags(&self) -> String {
72        let mut flags = Vec::new();
73        if self.keep_data {
74            flags.push("-k");
75        }
76        if self.shared {
77            flags.push("-s");
78        }
79        flags.join(" ")
80    }
81}
82
83#[cfg(test)]
84mod tests {
85    use super::*;
86
87    #[test]
88    fn test_install_options() {
89        let opts = InstallOptions::new().replace(true);
90        assert_eq!(opts.to_flags(), "-r");
91
92        let opts = InstallOptions::new().replace(true).shared(true);
93        assert_eq!(opts.to_flags(), "-r -s");
94    }
95
96    #[test]
97    fn test_uninstall_options() {
98        let opts = UninstallOptions::new().keep_data(true);
99        assert_eq!(opts.to_flags(), "-k");
100
101        let opts = UninstallOptions::new().keep_data(true).shared(true);
102        assert_eq!(opts.to_flags(), "-k -s");
103    }
104}