#[derive(Debug, Clone, Default)]
pub struct InstallOptions {
pub replace: bool,
pub shared: bool,
}
impl InstallOptions {
pub fn new() -> Self {
Self::default()
}
pub fn replace(mut self, replace: bool) -> Self {
self.replace = replace;
self
}
pub fn shared(mut self, shared: bool) -> Self {
self.shared = shared;
self
}
pub fn to_flags(&self) -> String {
let mut flags = Vec::new();
if self.replace {
flags.push("-r");
}
if self.shared {
flags.push("-s");
}
flags.join(" ")
}
}
#[derive(Debug, Clone, Default)]
pub struct UninstallOptions {
pub keep_data: bool,
pub shared: bool,
}
impl UninstallOptions {
pub fn new() -> Self {
Self::default()
}
pub fn keep_data(mut self, keep: bool) -> Self {
self.keep_data = keep;
self
}
pub fn shared(mut self, shared: bool) -> Self {
self.shared = shared;
self
}
pub fn to_flags(&self) -> String {
let mut flags = Vec::new();
if self.keep_data {
flags.push("-k");
}
if self.shared {
flags.push("-s");
}
flags.join(" ")
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_install_options() {
let opts = InstallOptions::new().replace(true);
assert_eq!(opts.to_flags(), "-r");
let opts = InstallOptions::new().replace(true).shared(true);
assert_eq!(opts.to_flags(), "-r -s");
}
#[test]
fn test_uninstall_options() {
let opts = UninstallOptions::new().keep_data(true);
assert_eq!(opts.to_flags(), "-k");
let opts = UninstallOptions::new().keep_data(true).shared(true);
assert_eq!(opts.to_flags(), "-k -s");
}
}