complete Pacman backend

This commit is contained in:
steven-omaha
2023-01-05 16:50:42 +01:00
parent 2f511cf87c
commit 0875881db1
2 changed files with 30 additions and 22 deletions
+28 -2
View File
@@ -1,6 +1,8 @@
mod pacman;
use std::collections::HashSet;
use std::os::unix::process::CommandExt;
use std::process::Command;
use crate::Package;
@@ -9,12 +11,36 @@ pub use pacman::Pacman;
pub trait Backend {
/// The binary that should be called to run the associated package manager.
const BINARY: &'static str;
/// The switches that signals the `BINARY` that the packages should be installed.
const SWITCH_INSTALL: &'static str;
/// The switches that signals the `BINARY` that the packages should be removed.
const SWITCH_REMOVE: &'static str;
/// Get all packages that are installed in the system.
fn get_all_installed_packages() -> HashSet<Package>;
/// Get all packages that were installed in the system explicitly.
fn get_explicitly_installed_packages() -> HashSet<Package>;
/// Install the specified packages.
fn install_packages(packages: Vec<Package>);
fn install_packages(packages: Vec<Package>) {
let mut cmd = Command::new(Self::BINARY);
cmd.arg(Self::SWITCH_INSTALL);
for p in packages {
cmd.arg(format!("{p}"));
}
cmd.exec();
}
/// Remove the specified packages.
fn remove_packages(packages: Vec<Package>);
fn remove_packages(packages: Vec<Package>) {
let mut cmd = Command::new(Self::BINARY);
cmd.arg(Self::SWITCH_REMOVE);
for p in packages {
cmd.arg(format!("{p}"));
}
cmd.exec();
}
}