diff options
Diffstat (limited to 'src/packages.rs')
-rw-r--r-- | src/packages.rs | 18 |
1 files changed, 4 insertions, 14 deletions
diff --git a/src/packages.rs b/src/packages.rs index 2eadcfc..de818f4 100644 --- a/src/packages.rs +++ b/src/packages.rs | |||
@@ -6,9 +6,7 @@ use serde::{Deserialize, Serialize}; | |||
6 | 6 | ||
7 | use crate::error::{Error, Result}; | 7 | use crate::error::{Error, Result}; |
8 | 8 | ||
9 | #[cfg(feature = "pacman")] | ||
10 | mod pacman; | 9 | mod pacman; |
11 | #[cfg(feature = "portage")] | ||
12 | mod portage; | 10 | mod portage; |
13 | 11 | ||
14 | #[derive(Debug, Serialize, Deserialize)] | 12 | #[derive(Debug, Serialize, Deserialize)] |
@@ -19,7 +17,9 @@ pub struct PackageList { | |||
19 | 17 | ||
20 | impl PackageList { | 18 | impl PackageList { |
21 | pub fn install(&self) -> Result<()> { | 19 | pub fn install(&self) -> Result<()> { |
22 | self.manager.to_package_manager().install(self.packages.clone()) | 20 | self.manager |
21 | .to_package_manager() | ||
22 | .install(self.packages.clone()) | ||
23 | } | 23 | } |
24 | } | 24 | } |
25 | 25 | ||
@@ -32,19 +32,14 @@ pub struct Package { | |||
32 | 32 | ||
33 | #[derive(Debug, Clone, clap::ValueEnum, Serialize, Deserialize)] | 33 | #[derive(Debug, Clone, clap::ValueEnum, Serialize, Deserialize)] |
34 | pub enum Manager { | 34 | pub enum Manager { |
35 | #[cfg(feature = "pacman")] | ||
36 | Pacman, | 35 | Pacman, |
37 | #[cfg(feature = "portage")] | ||
38 | Portage, | 36 | Portage, |
39 | } | 37 | } |
40 | 38 | ||
41 | |||
42 | impl Manager { | 39 | impl Manager { |
43 | pub fn get_manager(manager: Option<Manager>) -> Result<Box<dyn PackageManager>> { | 40 | pub fn get_manager(manager: Option<Manager>) -> Result<Box<dyn PackageManager>> { |
44 | #[cfg(not(target_os = "linux"))] | 41 | #[cfg(not(target_os = "linux"))] |
45 | { | 42 | return Err(Error::Unsupported); |
46 | return Err(Error::Unsupported); | ||
47 | } | ||
48 | 43 | ||
49 | #[cfg(target_os = "linux")] | 44 | #[cfg(target_os = "linux")] |
50 | { | 45 | { |
@@ -70,9 +65,7 @@ impl Manager { | |||
70 | 65 | ||
71 | fn from_str(value: &str) -> Result<Box<dyn PackageManager>> { | 66 | fn from_str(value: &str) -> Result<Box<dyn PackageManager>> { |
72 | Ok(match value { | 67 | Ok(match value { |
73 | #[cfg(feature = "pacman")] | ||
74 | "arch" => Box::new(Pacman), | 68 | "arch" => Box::new(Pacman), |
75 | #[cfg(feature = "portage")] | ||
76 | "gentoo" => Box::new(Portage), | 69 | "gentoo" => Box::new(Portage), |
77 | _ => return Err(Error::Unsupported), | 70 | _ => return Err(Error::Unsupported), |
78 | }) | 71 | }) |
@@ -80,15 +73,12 @@ impl Manager { | |||
80 | 73 | ||
81 | fn to_package_manager(&self) -> Box<dyn PackageManager> { | 74 | fn to_package_manager(&self) -> Box<dyn PackageManager> { |
82 | match self { | 75 | match self { |
83 | #[cfg(feature = "pacman")] | ||
84 | Self::Pacman => Box::new(Pacman), | 76 | Self::Pacman => Box::new(Pacman), |
85 | #[cfg(feature = "portage")] | ||
86 | Self::Portage => Box::new(Portage), | 77 | Self::Portage => Box::new(Portage), |
87 | } | 78 | } |
88 | } | 79 | } |
89 | } | 80 | } |
90 | 81 | ||
91 | |||
92 | pub trait PackageManager { | 82 | pub trait PackageManager { |
93 | fn get_installed(&self) -> Result<PackageList>; | 83 | fn get_installed(&self) -> Result<PackageList>; |
94 | 84 | ||