1use crate::{pacmanconf, Config, Error};
2
3#[derive(Debug, Clone, PartialEq, Eq, Default)]
5pub struct Options {
6 conf_binrary: Option<String>,
7 pacman_conf: Option<String>,
8 root_dir: Option<String>,
9}
10
11impl Config {
12 pub fn options() -> Options {
15 Options::new()
16 }
17}
18
19impl Options {
20 pub fn new() -> Self {
23 Default::default()
24 }
25
26 pub fn pacman_conf_bin<S: Into<String>>(&mut self, s: S) -> &mut Self {
28 self.conf_binrary = Some(s.into());
29 self
30 }
31
32 pub fn pacman_conf<S: Into<String>>(&mut self, s: S) -> &mut Self {
35 self.pacman_conf = Some(s.into());
36 self
37 }
38
39 pub fn root_dir<S: Into<String>>(&mut self, s: S) -> &mut Self {
41 self.root_dir = Some(s.into());
42 self
43 }
44
45 pub fn read(&self) -> Result<Config, Error> {
47 pacmanconf::Config::with_opts(
48 self.conf_binrary.as_ref(),
49 self.pacman_conf.as_ref(),
50 self.root_dir.as_ref(),
51 )
52 }
53
54 pub fn expand(&self) -> Result<String, Error> {
56 pacmanconf::Config::expand_with_opts(
57 self.conf_binrary.as_ref(),
58 self.pacman_conf.as_ref(),
59 self.root_dir.as_ref(),
60 )
61 }
62}