use crate::{pacmanconf, Config, Error};
#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct Options {
conf_binrary: Option<String>,
pacman_conf: Option<String>,
root_dir: Option<String>,
}
impl Config {
pub fn options() -> Options {
Options::new()
}
}
impl Options {
pub fn new() -> Self {
Default::default()
}
pub fn pacman_conf_bin<S: Into<String>>(&mut self, s: S) -> &mut Self {
self.conf_binrary = Some(s.into());
self
}
pub fn pacman_conf<S: Into<String>>(&mut self, s: S) -> &mut Self {
self.pacman_conf = Some(s.into());
self
}
pub fn root_dir<S: Into<String>>(&mut self, s: S) -> &mut Self {
self.root_dir = Some(s.into());
self
}
pub fn read(&self) -> Result<Config, Error> {
pacmanconf::Config::with_opts(
self.conf_binrary.as_ref(),
self.pacman_conf.as_ref(),
self.root_dir.as_ref(),
)
}
pub fn expand(&self) -> Result<String, Error> {
pacmanconf::Config::expand_with_opts(
self.conf_binrary.as_ref(),
self.pacman_conf.as_ref(),
self.root_dir.as_ref(),
)
}
}