summaryrefslogtreecommitdiff
path: root/src/packages/pacman.rs
blob: 0a9e1ff15e3825613f13eb63273e3349b2050ec3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
use std::process::Command;

use crate::packages::Package;

use super::PackageManager;

pub struct Pacman;

impl PackageManager for Pacman {
    fn get_installed(&self) -> Vec<super::Package> {
        let pm_pkgs = Command::new("pacman").args(["-Q"]).output().unwrap();
        let pm_e_pkgs = Command::new("pacman")
            .args(["-Q", "--explicit"])
            .output()
            .unwrap();

        let pm_pkgs_out = String::from_utf8(pm_pkgs.stdout).unwrap();
        let pm_e_pkgs_out = String::from_utf8(pm_e_pkgs.stdout).unwrap();

        let mut pkgs: Vec<Package> = Vec::new();
        let pacman_pkgs: Vec<&str> = pm_pkgs_out.split('\n').collect();
        for pkg in pacman_pkgs {
            if pkg.is_empty() {
                continue;
            };
            let split: Vec<&str> = pkg.split_whitespace().collect();
            if split.len() != 2 {
                panic!("Unknown Pacman Output");
            };

            let explicit = pm_e_pkgs_out.contains(pkg);

            pkgs.push(Package {
                id: split[0].to_string(),
                version: split[1].to_string(),
                explicit
            })
        }

        pkgs
    }

    fn install(&self, pkgs: Vec<Package>) {
        todo!();
    }
}