summaryrefslogtreecommitdiff
path: root/src/packages.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/packages.rs')
-rw-r--r--src/packages.rs13
1 files changed, 5 insertions, 8 deletions
diff --git a/src/packages.rs b/src/packages.rs
index de818f4..41b9478 100644
--- a/src/packages.rs
+++ b/src/packages.rs
@@ -37,15 +37,12 @@ pub enum Manager {
37} 37}
38 38
39impl Manager { 39impl Manager {
40 pub fn get_manager(manager: Option<Manager>) -> Result<Box<dyn PackageManager>> { 40 pub fn from_sys() -> Result<Self> {
41 #[cfg(not(target_os = "linux"))] 41 #[cfg(not(target_os = "linux"))]
42 return Err(Error::Unsupported); 42 return Err(Error::Unsupported);
43 43
44 #[cfg(target_os = "linux")] 44 #[cfg(target_os = "linux")]
45 { 45 {
46 if let Some(man) = manager {
47 return Ok(man.to_package_manager());
48 }
49 let mut os_release = File::open("/etc/os-release")?; 46 let mut os_release = File::open("/etc/os-release")?;
50 let mut content = String::new(); 47 let mut content = String::new();
51 os_release.read_to_string(&mut content)?; 48 os_release.read_to_string(&mut content)?;
@@ -63,15 +60,15 @@ impl Manager {
63 } 60 }
64 } 61 }
65 62
66 fn from_str(value: &str) -> Result<Box<dyn PackageManager>> { 63 fn from_str(value: &str) -> Result<Self> {
67 Ok(match value { 64 Ok(match value {
68 "arch" => Box::new(Pacman), 65 "arch" => Self::Pacman,
69 "gentoo" => Box::new(Portage), 66 "gentoo" => Self::Portage,
70 _ => return Err(Error::Unsupported), 67 _ => return Err(Error::Unsupported),
71 }) 68 })
72 } 69 }
73 70
74 fn to_package_manager(&self) -> Box<dyn PackageManager> { 71 pub fn to_package_manager(&self) -> Box<dyn PackageManager> {
75 match self { 72 match self {
76 Self::Pacman => Box::new(Pacman), 73 Self::Pacman => Box::new(Pacman),
77 Self::Portage => Box::new(Portage), 74 Self::Portage => Box::new(Portage),