1#[derive(Debug, Clone, Default)]
5pub struct InstallOptions {
6 pub replace: bool,
8 pub shared: bool,
10}
11
12impl InstallOptions {
13 pub fn new() -> Self {
15 Self::default()
16 }
17
18 pub fn replace(mut self, replace: bool) -> Self {
20 self.replace = replace;
21 self
22 }
23
24 pub fn shared(mut self, shared: bool) -> Self {
26 self.shared = shared;
27 self
28 }
29
30 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#[derive(Debug, Clone, Default)]
45pub struct UninstallOptions {
46 pub keep_data: bool,
48 pub shared: bool,
50}
51
52impl UninstallOptions {
53 pub fn new() -> Self {
55 Self::default()
56 }
57
58 pub fn keep_data(mut self, keep: bool) -> Self {
60 self.keep_data = keep;
61 self
62 }
63
64 pub fn shared(mut self, shared: bool) -> Self {
66 self.shared = shared;
67 self
68 }
69
70 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}