Skip to content

Commit

Permalink
feat(paru): support paru (#387)
Browse files Browse the repository at this point in the history
  • Loading branch information
Qelxiros authored and tversteeg committed May 25, 2024
1 parent e5f72c9 commit 20229c8
Show file tree
Hide file tree
Showing 3 changed files with 131 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
| <img src="https://cdn.rawgit.com/simple-icons/simple-icons/develop/icons/linux.svg" width="18" height="18" /> | GNU Guix |
| <img src="https://cdn.rawgit.com/simple-icons/simple-icons/develop/icons/nixos.svg" width="18" height="18" /><img src="https://cdn.rawgit.com/simple-icons/simple-icons/develop/icons/linux.svg" width="18" height="18" /><img src="https://cdn.rawgit.com/simple-icons/simple-icons/develop/icons/apple.svg" width="18" height="18" /> | Nix |
| <img src="https://cdn.rawgit.com/simple-icons/simple-icons/develop/icons/archlinux.svg" width="18" height="18" /> | Pacman |
| <img src="https://cdn.rawgit.com/simple-icons/simple-icons/develop/icons/archlinux.svg" width="18" height="18" /> | Paru |
| <img src="https://cdn.rawgit.com/simple-icons/simple-icons/develop/icons/archlinux.svg" width="18" height="18" /> | RUA |
| <img src="https://cdn.rawgit.com/simple-icons/simple-icons/develop/icons/archlinux.svg" width="18" height="18" /> | Yay |
| <img src="https://cdn.rawgit.com/simple-icons/simple-icons/develop/icons/suse.svg" width="18" height="18" /> | Zypper |
Expand Down Expand Up @@ -151,6 +152,8 @@ sudo apt install meld
# -- or --
pacman -S zsh
# -- or --
paru -S ventoy
# -- or --
rua install peek
# -- or --
yay -S thunar
Expand Down
3 changes: 3 additions & 0 deletions src/package_manager/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ mod guix;
mod nix;
mod npm;
mod pacman;
mod paru;
mod pip;
mod pip3;
mod pkg;
Expand All @@ -35,6 +36,7 @@ pub use guix::Guix;
pub use nix::Nix;
pub use npm::Npm;
pub use pacman::Pacman;
pub use paru::Paru;
pub use pip::Pip;
pub use pip3::Pip3;
pub use pkg::Pkg;
Expand Down Expand Up @@ -67,6 +69,7 @@ pub enum PackageManager {
Nix,
Npm,
Pacman,
Paru,
Pip,
Pip3,
Pkg,
Expand Down
125 changes: 125 additions & 0 deletions src/package_manager/paru.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
use super::{CaptureFlag, PackageInstalledMethod, PackageManagerTrait};
use serde::{Deserialize, Serialize};

#[derive(Debug, Default, Copy, Clone, Eq, PartialEq, Serialize, Deserialize)]
pub struct Paru;

impl PackageManagerTrait for Paru {
fn full_name(self) -> &'static str {
"Paru"
}

fn commands(self) -> Vec<&'static str> {
vec!["paru"]
}

fn sub_commands(self) -> Vec<&'static str> {
vec!["-S"]
}

fn install_command(self) -> &'static str {
"paru -S --noconfirm --quiet"
}

fn needs_root(self) -> bool {
true
}

fn is_installed(self, package: &str) -> PackageInstalledMethod {
PackageInstalledMethod::Script(format!("paru -Q {}", package))
}

fn known_flags_with_values(self) -> Vec<&'static str> {
vec![
// inherited from pacman
"-b",
"--dbpath",
"-r",
"--root",
"--arch",
"--cachedir",
"--color",
"--config",
"--gpgdir",
"--hookdir",
"--logfile",
"--sysroot",
"--assume-installed",
"--print-format",
"--ignore",
"--ignoregroup",
"--overwrite",
"-o",
"--owns",
"-s",
"--search",
"--asdeps",
"--asexplicit",
// new in paru
"--clonedir",
"--makepkg",
"--makepkgconf",
"--pacman",
"--pacman-conf",
"--git",
"--gitflags",
"--gpg",
"--gpgflags",
"--fm",
"--asp",
"--mflags",
"--bat",
"--batflags",
"--sudo",
"--sudoflags",
"--chrootflags",
"--completioninterval",
"--sortby",
"--searchby",
"--removemake",
"--limit",
"--redownload",
"--rebuild",
"--sudoloop",
"--localrepo",
"--chroot",
"--sign",
"--signdb",
]
}

fn capture_flags(self) -> Vec<CaptureFlag> {
vec![]
}

fn invalidating_flags(self) -> Vec<&'static str> {
vec![]
}
}

#[cfg(test)]
mod tests {
use super::Paru;
use crate::{catch, package_manager::PackageManager};

#[test]
fn test_package_manager() {
let manager = PackageManager::single_from_line("paru -S test").unwrap();
assert_eq!(manager, PackageManager::from(Paru));
}

#[test]
fn test_catch() {
// Regular invocation
catch!(PackageManager::from(Paru), "sudo paru -S test" => "test");
catch!(PackageManager::from(Paru), "paru -S test" => "test");
catch!(PackageManager::from(Paru), "sudo paru -S lib32gfortran5-x32-cross" => "lib32gfortran5-x32-cross");
catch!(PackageManager::from(Paru), "sudo paru -S linux-perf-5.3" => "linux-perf-5.3");

// Multiple
catch!(PackageManager::from(Paru), "sudo paru -S test test2" => "test", "test2");

// Ignore
catch!(PackageManager::from(Paru), "sudo paru test test2" => ());
}
}

0 comments on commit 20229c8

Please sign in to comment.