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