summaryrefslogtreecommitdiff
path: root/src/packages/pacman.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/packages/pacman.rs')
-rw-r--r--src/packages/pacman.rs46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/packages/pacman.rs b/src/packages/pacman.rs
new file mode 100644
index 0000000..0a9e1ff
--- /dev/null
+++ b/src/packages/pacman.rs
@@ -0,0 +1,46 @@
1use std::process::Command;
2
3use crate::packages::Package;
4
5use super::PackageManager;
6
7pub struct Pacman;
8
9impl PackageManager for Pacman {
10 fn get_installed(&self) -> Vec<super::Package> {
11 let pm_pkgs = Command::new("pacman").args(["-Q"]).output().unwrap();
12 let pm_e_pkgs = Command::new("pacman")
13 .args(["-Q", "--explicit"])
14 .output()
15 .unwrap();
16
17 let pm_pkgs_out = String::from_utf8(pm_pkgs.stdout).unwrap();
18 let pm_e_pkgs_out = String::from_utf8(pm_e_pkgs.stdout).unwrap();
19
20 let mut pkgs: Vec<Package> = Vec::new();
21 let pacman_pkgs: Vec<&str> = pm_pkgs_out.split('\n').collect();
22 for pkg in pacman_pkgs {
23 if pkg.is_empty() {
24 continue;
25 };
26 let split: Vec<&str> = pkg.split_whitespace().collect();
27 if split.len() != 2 {
28 panic!("Unknown Pacman Output");
29 };
30
31 let explicit = pm_e_pkgs_out.contains(pkg);
32
33 pkgs.push(Package {
34 id: split[0].to_string(),
35 version: split[1].to_string(),
36 explicit
37 })
38 }
39
40 pkgs
41 }
42
43 fn install(&self, pkgs: Vec<Package>) {
44 todo!();
45 }
46}