add install and remove packages to Backend trait
This commit is contained in:
@@ -7,8 +7,14 @@ use crate::Package;
|
||||
pub use pacman::Pacman;
|
||||
|
||||
pub trait Backend {
|
||||
/// The binary that should be called to run the associated package manager.
|
||||
const BINARY: &'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>);
|
||||
/// Remove the specified packages.
|
||||
fn remove_packages(packages: Vec<Package>);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
use std::collections::HashSet;
|
||||
use std::os::unix::process::CommandExt;
|
||||
use std::process::Command;
|
||||
|
||||
use alpm::Alpm;
|
||||
use alpm::PackageReason::Explicit;
|
||||
@@ -9,6 +11,8 @@ use crate::Package;
|
||||
pub struct Pacman;
|
||||
|
||||
impl Backend for Pacman {
|
||||
const BINARY: &'static str = "paru";
|
||||
|
||||
fn get_all_installed_packages() -> HashSet<Package> {
|
||||
convert_to_pacdef_packages(get_all_installed_packages_from_alpm())
|
||||
}
|
||||
@@ -16,6 +20,24 @@ impl Backend for Pacman {
|
||||
fn get_explicitly_installed_packages() -> HashSet<Package> {
|
||||
convert_to_pacdef_packages(get_explicitly_installed_packages_from_alpm())
|
||||
}
|
||||
|
||||
fn install_packages(packages: Vec<Package>) {
|
||||
let mut cmd = Command::new("paru");
|
||||
cmd.arg("-S");
|
||||
for p in packages {
|
||||
cmd.arg(format!("{p}"));
|
||||
}
|
||||
cmd.exec();
|
||||
}
|
||||
|
||||
fn remove_packages(packages: Vec<Package>) {
|
||||
let mut cmd = Command::new("paru");
|
||||
cmd.arg("-Rsn");
|
||||
for p in packages {
|
||||
cmd.arg(format!("{p}"));
|
||||
}
|
||||
cmd.exec();
|
||||
}
|
||||
}
|
||||
|
||||
fn get_all_installed_packages_from_alpm() -> HashSet<String> {
|
||||
|
||||
Reference in New Issue
Block a user