From 1b99a4a1ed7772c9b68e59f46e493ea5b4715239 Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Sat, 14 Sep 2024 14:20:52 +0200 Subject: add portage package manager --- src/packages.rs | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) (limited to 'src/packages.rs') 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}; use crate::error::{Error, Result}; -#[cfg(feature = "pacman")] mod pacman; -#[cfg(feature = "portage")] mod portage; #[derive(Debug, Serialize, Deserialize)] @@ -19,7 +17,9 @@ pub struct PackageList { impl PackageList { pub fn install(&self) -> Result<()> { - self.manager.to_package_manager().install(self.packages.clone()) + self.manager + .to_package_manager() + .install(self.packages.clone()) } } @@ -32,19 +32,14 @@ pub struct Package { #[derive(Debug, Clone, clap::ValueEnum, Serialize, Deserialize)] pub enum Manager { - #[cfg(feature = "pacman")] Pacman, - #[cfg(feature = "portage")] Portage, } - impl Manager { pub fn get_manager(manager: Option) -> Result> { #[cfg(not(target_os = "linux"))] - { - return Err(Error::Unsupported); - } + return Err(Error::Unsupported); #[cfg(target_os = "linux")] { @@ -70,9 +65,7 @@ impl Manager { fn from_str(value: &str) -> Result> { Ok(match value { - #[cfg(feature = "pacman")] "arch" => Box::new(Pacman), - #[cfg(feature = "portage")] "gentoo" => Box::new(Portage), _ => return Err(Error::Unsupported), }) @@ -80,15 +73,12 @@ impl Manager { fn to_package_manager(&self) -> Box { match self { - #[cfg(feature = "pacman")] Self::Pacman => Box::new(Pacman), - #[cfg(feature = "portage")] Self::Portage => Box::new(Portage), } } } - pub trait PackageManager { fn get_installed(&self) -> Result; -- cgit v1.2.3