Skip to content

Commit

Permalink
deduplicate the arch backends
Browse files Browse the repository at this point in the history
  • Loading branch information
ripytide committed Sep 29, 2024
1 parent 9632d67 commit d77e010
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 31 deletions.
4 changes: 1 addition & 3 deletions groups/example_group.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
pacman = ["pacdef", { package = "pacdef", optional_deps = ["git"] }]
yay = ["pacdef", { package = "pacdef", optional_deps = ["git"] }]
paru = ["pacdef", { package = "pacdef", optional_deps = ["git"] }]
arch = ["pacdef", { package = "pacdef", optional_deps = ["git"] }]
cargo = [
"pacdef",
{ package = "pacdef", version = "0.1.0", git = "https://github.com/ripytide/pacdef", all_features = true, no_default_features = false, features = [
Expand Down
37 changes: 18 additions & 19 deletions src/backends/arch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ use crate::prelude::*;
#[derive(Debug, Copy, Clone, Default, PartialEq, Eq, PartialOrd, Ord, derive_more::Display)]
pub struct Arch;

pub type ArchPackageId = String;

#[derive(Debug, Clone)]
pub struct ArchQueryInfo {
pub explicit: bool,
Expand All @@ -26,17 +24,22 @@ pub struct ArchModificationOptions {
#[derive(Debug, Clone, Default, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
pub struct ArchInstallOptions {
#[serde_inline_default(ArchInstallOptions::default().optional_deps)]
pub optional_deps: Vec<ArchPackageId>,
pub optional_deps: Vec<String>,
}

#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct ArchRemoveOptions {}

impl Arch {
pub fn query_installed_packages(
&self,
impl Backend for Arch {
type PackageId = String;
type QueryInfo = ArchQueryInfo;
type InstallOptions = ArchInstallOptions;
type ModificationOptions = ArchModificationOptions;
type RemoveOptions = ArchRemoveOptions;

fn query_installed_packages(
config: &Config,
) -> Result<BTreeMap<ArchPackageId, ArchQueryInfo>> {
) -> Result<BTreeMap<Self::PackageId, Self::QueryInfo>> {
if !command_found(&config.arch_package_manager) {
return Ok(BTreeMap::new());
}
Expand Down Expand Up @@ -66,9 +69,8 @@ impl Arch {
.collect())
}

pub fn install_packages(
&self,
packages: &BTreeMap<ArchPackageId, ArchInstallOptions>,
fn install_packages(
packages: &BTreeMap<Self::PackageId, Self::InstallOptions>,
no_confirm: bool,
config: &Config,
) -> Result<()> {
Expand All @@ -84,9 +86,8 @@ impl Arch {
)
}

pub fn modify_packages(
&self,
packages: &BTreeMap<ArchPackageId, ArchModificationOptions>,
fn modify_packages(
packages: &BTreeMap<Self::PackageId, Self::ModificationOptions>,
config: &Config,
) -> Result<()> {
run_command(
Expand All @@ -102,9 +103,8 @@ impl Arch {
)
}

pub fn remove_packages(
&self,
packages: &BTreeMap<ArchPackageId, ArchRemoveOptions>,
fn remove_packages(
packages: &BTreeMap<Self::PackageId, Self::RemoveOptions>,
no_confirm: bool,
config: &Config,
) -> Result<()> {
Expand All @@ -118,10 +118,9 @@ impl Arch {
)
}

pub fn try_parse_toml_package(
&self,
fn try_parse_toml_package(
toml: &toml::Value,
) -> Result<(ArchPackageId, ArchInstallOptions)> {
) -> Result<(Self::PackageId, Self::InstallOptions)> {
match toml {
toml::Value::String(x) => Ok((x.to_string(), Default::default())),
toml::Value::Table(x) => Ok((
Expand Down
5 changes: 1 addition & 4 deletions src/backends/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@ pub mod arch;
pub mod cargo;
pub mod dnf;
pub mod flatpak;
pub mod pacman;
pub mod paru;
pub mod pip;
pub mod pipx;
pub mod rustup;
pub mod xbps;
pub mod yay;

use std::collections::BTreeMap;

Expand All @@ -20,7 +17,7 @@ use serde::{Deserialize, Serialize};

macro_rules! apply_public_backends {
($macro:ident) => {
$macro! { Apt, Cargo, Dnf, Flatpak, Pacman, Paru, Pip, Pipx, Rustup, Xbps, Yay }
$macro! { Arch, Apt, Cargo, Dnf, Flatpak, Pip, Pipx, Rustup, Xbps }
};
}
pub(crate) use apply_public_backends;
Expand Down
6 changes: 1 addition & 5 deletions src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,17 @@ pub use crate::backends::all::{
pub(crate) use crate::backends::apply_public_backends;
pub use crate::backends::apt::{Apt, AptModificationOptions, AptQueryInfo};
pub use crate::backends::arch::{
Arch, ArchInstallOptions, ArchModificationOptions, ArchPackageId, ArchQueryInfo,
ArchRemoveOptions,
Arch, ArchInstallOptions, ArchModificationOptions, ArchQueryInfo, ArchRemoveOptions,
};
pub use crate::backends::cargo::Cargo;
pub use crate::backends::dnf::{Dnf, DnfInstallOptions, DnfQueryInfo};
pub use crate::backends::flatpak::{Flatpak, FlatpakQueryInfo};
pub use crate::backends::pacman::Pacman;
pub use crate::backends::paru::Paru;
pub use crate::backends::pip::{Pip, PipQueryInfo};
pub use crate::backends::pipx::Pipx;
pub use crate::backends::rustup::{
Rustup, RustupInstallOptions, RustupModificationOptions, RustupQueryInfo,
};
pub use crate::backends::xbps::{Xbps, XbpsModificationOptions};
pub use crate::backends::yay::Yay;
pub use crate::backends::Backend;
pub use crate::backends::StringPackageStruct;
pub use crate::cli::CleanPackageAction;
Expand Down

0 comments on commit d77e010

Please sign in to comment.