diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/packages.rs | 5 | ||||
-rw-r--r-- | src/packages/dnf.rs | 50 |
2 files changed, 55 insertions, 0 deletions
diff --git a/src/packages.rs b/src/packages.rs index de818f4..2844a9b 100644 --- a/src/packages.rs +++ b/src/packages.rs | |||
@@ -1,11 +1,13 @@ | |||
1 | use std::{fs::File, io::Read}; | 1 | use std::{fs::File, io::Read}; |
2 | 2 | ||
3 | use dnf::Dnf; | ||
3 | use pacman::Pacman; | 4 | use pacman::Pacman; |
4 | use portage::Portage; | 5 | use portage::Portage; |
5 | use serde::{Deserialize, Serialize}; | 6 | use serde::{Deserialize, Serialize}; |
6 | 7 | ||
7 | use crate::error::{Error, Result}; | 8 | use crate::error::{Error, Result}; |
8 | 9 | ||
10 | mod dnf; | ||
9 | mod pacman; | 11 | mod pacman; |
10 | mod portage; | 12 | mod portage; |
11 | 13 | ||
@@ -32,6 +34,7 @@ pub struct Package { | |||
32 | 34 | ||
33 | #[derive(Debug, Clone, clap::ValueEnum, Serialize, Deserialize)] | 35 | #[derive(Debug, Clone, clap::ValueEnum, Serialize, Deserialize)] |
34 | pub enum Manager { | 36 | pub enum Manager { |
37 | Dnf, | ||
35 | Pacman, | 38 | Pacman, |
36 | Portage, | 39 | Portage, |
37 | } | 40 | } |
@@ -65,6 +68,7 @@ impl Manager { | |||
65 | 68 | ||
66 | fn from_str(value: &str) -> Result<Box<dyn PackageManager>> { | 69 | fn from_str(value: &str) -> Result<Box<dyn PackageManager>> { |
67 | Ok(match value { | 70 | Ok(match value { |
71 | "fedora" => Box::new(Dnf), | ||
68 | "arch" => Box::new(Pacman), | 72 | "arch" => Box::new(Pacman), |
69 | "gentoo" => Box::new(Portage), | 73 | "gentoo" => Box::new(Portage), |
70 | _ => return Err(Error::Unsupported), | 74 | _ => return Err(Error::Unsupported), |
@@ -73,6 +77,7 @@ impl Manager { | |||
73 | 77 | ||
74 | fn to_package_manager(&self) -> Box<dyn PackageManager> { | 78 | fn to_package_manager(&self) -> Box<dyn PackageManager> { |
75 | match self { | 79 | match self { |
80 | Self::Dnf => Box::new(Dnf), | ||
76 | Self::Pacman => Box::new(Pacman), | 81 | Self::Pacman => Box::new(Pacman), |
77 | Self::Portage => Box::new(Portage), | 82 | Self::Portage => Box::new(Portage), |
78 | } | 83 | } |
diff --git a/src/packages/dnf.rs b/src/packages/dnf.rs new file mode 100644 index 0000000..aad9c8f --- /dev/null +++ b/src/packages/dnf.rs | |||
@@ -0,0 +1,50 @@ | |||
1 | use std::process::Command; | ||
2 | |||
3 | use super::{Package, PackageList, PackageManager}; | ||
4 | |||
5 | use crate::error::{Error, Result}; | ||
6 | |||
7 | pub struct Dnf; | ||
8 | |||
9 | impl PackageManager for Dnf { | ||
10 | fn get_installed(&self) -> Result<PackageList> { | ||
11 | let list = Command::new("dnf").args(["list", "installed"]).output().unwrap(); | ||
12 | let explicit_list = Command::new("dnf").args(["repoquery", "--userinstalled"]).output().unwrap(); | ||
13 | |||
14 | let list_str = String::from_utf8(list.stdout).unwrap(); | ||
15 | let ex_list_str = String::from_utf8(explicit_list.stdout).unwrap(); | ||
16 | |||
17 | |||
18 | let mut pkgs: Vec<Package> = Vec::new(); | ||
19 | let list_lines: Vec<&str> = list_str.split('\n').collect(); | ||
20 | // Pop first info line | ||
21 | let list_lines = &list_lines[1..list_lines.len()]; | ||
22 | for pkg in list_lines { | ||
23 | if pkg.is_empty() { | ||
24 | continue; | ||
25 | }; | ||
26 | let split: Vec<&str> = pkg.split_whitespace().collect(); | ||
27 | if split.len() != 3 { | ||
28 | return Err(Error::UnknownOutput); | ||
29 | }; | ||
30 | |||
31 | let explicit = ex_list_str.contains(pkg); | ||
32 | |||
33 | let Some(pkg_id) = split[0].split_once('.') else { | ||
34 | return Err(Error::UnknownOutput); | ||
35 | }; | ||
36 | pkgs.push(Package { | ||
37 | id: pkg_id.0.to_string(), | ||
38 | version: split[1].to_string(), | ||
39 | explicit, | ||
40 | }); | ||
41 | } | ||
42 | |||
43 | Ok(PackageList { | ||
44 | packages: pkgs, | ||
45 | manager: super::Manager::Dnf, | ||
46 | }) | ||
47 | } | ||
48 | |||
49 | fn install(&self, _pkgs: Vec<super::Package>) -> Result<()> { todo!() } | ||
50 | } | ||