Revert "add more generic backend stuff"

This reverts commit 265d67089b.
This commit is contained in:
timeshifter
2023-01-06 11:50:57 +01:00
parent e873cb979c
commit 0dcf3822eb
3 changed files with 17 additions and 57 deletions
+11 -35
View File
@@ -8,50 +8,29 @@ use std::process::Command;
use crate::Package;
pub use pacman::Pacman;
use rust::Rust;
pub fn get_backends() -> Vec<Box<dyn Backend>> {
let pacman = Pacman;
let rust = Rust;
vec![Box::new(pacman), Box::new(rust)]
}
type Switches = &'static [&'static str];
type Binary = &'static str;
pub trait Backend {
/// The binary that should be called to run the associated package manager.
fn get_binary() -> Binary
where
Self: Sized;
const BINARY: Binary;
/// The switches that signals the `BINARY` that the packages should be installed.
fn get_switches_install() -> Switches
where
Self: Sized;
const SWITCHES_INSTALL: Switches;
/// The switches that signals the `BINARY` that the packages should be removed.
fn get_switches_remove() -> Switches
where
Self: Sized;
const SWITCHES_REMOVE: Switches;
/// Get all packages that are installed in the system.
fn get_all_installed_packages() -> HashSet<Package>
where
Self: Sized;
fn get_all_installed_packages() -> HashSet<Package>;
/// Get all packages that were installed in the system explicitly.
fn get_explicitly_installed_packages() -> HashSet<Package>
where
Self: Sized;
fn get_explicitly_installed_packages() -> HashSet<Package>;
/// Install the specified packages.
fn install_packages(packages: Vec<Package>)
where
Self: Sized,
{
let mut cmd = Command::new(Self::get_binary());
cmd.args(Self::get_switches_install());
fn install_packages(packages: Vec<Package>) {
let mut cmd = Command::new(Self::BINARY);
cmd.args(Self::SWITCHES_INSTALL);
for p in packages {
cmd.arg(format!("{p}"));
}
@@ -59,12 +38,9 @@ pub trait Backend {
}
/// Remove the specified packages.
fn remove_packages(packages: Vec<Package>)
where
Self: Sized,
{
let mut cmd = Command::new(Self::get_binary());
cmd.args(Self::get_switches_remove());
fn remove_packages(packages: Vec<Package>) {
let mut cmd = Command::new(Self::BINARY);
cmd.args(Self::SWITCHES_REMOVE);
for p in packages {
cmd.arg(format!("{p}"));
}