Revert "add more generic backend stuff"
This reverts commit 265d67089b.
This commit is contained in:
+11
-35
@@ -8,50 +8,29 @@ use std::process::Command;
|
|||||||
use crate::Package;
|
use crate::Package;
|
||||||
|
|
||||||
pub use pacman::Pacman;
|
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 Switches = &'static [&'static str];
|
||||||
type Binary = &'static str;
|
type Binary = &'static str;
|
||||||
|
|
||||||
pub trait Backend {
|
pub trait Backend {
|
||||||
/// The binary that should be called to run the associated package manager.
|
/// The binary that should be called to run the associated package manager.
|
||||||
fn get_binary() -> Binary
|
const BINARY: Binary;
|
||||||
where
|
|
||||||
Self: Sized;
|
|
||||||
|
|
||||||
/// The switches that signals the `BINARY` that the packages should be installed.
|
/// The switches that signals the `BINARY` that the packages should be installed.
|
||||||
fn get_switches_install() -> Switches
|
const SWITCHES_INSTALL: Switches;
|
||||||
where
|
|
||||||
Self: Sized;
|
|
||||||
|
|
||||||
/// The switches that signals the `BINARY` that the packages should be removed.
|
/// The switches that signals the `BINARY` that the packages should be removed.
|
||||||
fn get_switches_remove() -> Switches
|
const SWITCHES_REMOVE: Switches;
|
||||||
where
|
|
||||||
Self: Sized;
|
|
||||||
|
|
||||||
/// Get all packages that are installed in the system.
|
/// Get all packages that are installed in the system.
|
||||||
fn get_all_installed_packages() -> HashSet<Package>
|
fn get_all_installed_packages() -> HashSet<Package>;
|
||||||
where
|
|
||||||
Self: Sized;
|
|
||||||
|
|
||||||
/// Get all packages that were installed in the system explicitly.
|
/// Get all packages that were installed in the system explicitly.
|
||||||
fn get_explicitly_installed_packages() -> HashSet<Package>
|
fn get_explicitly_installed_packages() -> HashSet<Package>;
|
||||||
where
|
|
||||||
Self: Sized;
|
|
||||||
|
|
||||||
/// Install the specified packages.
|
/// Install the specified packages.
|
||||||
fn install_packages(packages: Vec<Package>)
|
fn install_packages(packages: Vec<Package>) {
|
||||||
where
|
let mut cmd = Command::new(Self::BINARY);
|
||||||
Self: Sized,
|
cmd.args(Self::SWITCHES_INSTALL);
|
||||||
{
|
|
||||||
let mut cmd = Command::new(Self::get_binary());
|
|
||||||
cmd.args(Self::get_switches_install());
|
|
||||||
for p in packages {
|
for p in packages {
|
||||||
cmd.arg(format!("{p}"));
|
cmd.arg(format!("{p}"));
|
||||||
}
|
}
|
||||||
@@ -59,12 +38,9 @@ pub trait Backend {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Remove the specified packages.
|
/// Remove the specified packages.
|
||||||
fn remove_packages(packages: Vec<Package>)
|
fn remove_packages(packages: Vec<Package>) {
|
||||||
where
|
let mut cmd = Command::new(Self::BINARY);
|
||||||
Self: Sized,
|
cmd.args(Self::SWITCHES_REMOVE);
|
||||||
{
|
|
||||||
let mut cmd = Command::new(Self::get_binary());
|
|
||||||
cmd.args(Self::get_switches_remove());
|
|
||||||
for p in packages {
|
for p in packages {
|
||||||
cmd.arg(format!("{p}"));
|
cmd.arg(format!("{p}"));
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-11
@@ -9,17 +9,9 @@ use crate::Package;
|
|||||||
pub struct Pacman;
|
pub struct Pacman;
|
||||||
|
|
||||||
impl Backend for Pacman {
|
impl Backend for Pacman {
|
||||||
fn get_binary() -> Binary {
|
const BINARY: Binary = "paru";
|
||||||
"paru"
|
const SWITCHES_INSTALL: Switches = &["-S"];
|
||||||
}
|
const SWITCHES_REMOVE: Switches = &["-Rsn"];
|
||||||
|
|
||||||
fn get_switches_install() -> Switches {
|
|
||||||
&["-S"]
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_switches_remove() -> Switches {
|
|
||||||
&["-Rsn"]
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_all_installed_packages() -> HashSet<Package> {
|
fn get_all_installed_packages() -> HashSet<Package> {
|
||||||
convert_to_pacdef_packages(get_all_installed_packages_from_alpm())
|
convert_to_pacdef_packages(get_all_installed_packages_from_alpm())
|
||||||
|
|||||||
+3
-11
@@ -6,17 +6,9 @@ use crate::Package;
|
|||||||
pub struct Rust;
|
pub struct Rust;
|
||||||
|
|
||||||
impl Backend for Rust {
|
impl Backend for Rust {
|
||||||
fn get_binary() -> Binary {
|
const BINARY: Binary = "cargo";
|
||||||
"cargo"
|
const SWITCHES_INSTALL: Switches = &["install"];
|
||||||
}
|
const SWITCHES_REMOVE: Switches = &["uninstall"];
|
||||||
|
|
||||||
fn get_switches_install() -> Switches {
|
|
||||||
&["install"]
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_switches_remove() -> Switches {
|
|
||||||
&["uninstall"]
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_all_installed_packages() -> HashSet<Package> {
|
fn get_all_installed_packages() -> HashSet<Package> {
|
||||||
extract_packages_names(&run_cargo_install_list())
|
extract_packages_names(&run_cargo_install_list())
|
||||||
|
|||||||
Reference in New Issue
Block a user