refact(fedora): Move fetch flags to constants

Move the flags required for get_installed_packages and
get_user_installed_packages to separate module constants.

Signed-off-by: innocentzero <isfarulhaque@proton.me>
This commit is contained in:
innocentzero
2024-04-12 17:34:04 +05:30
parent 027a27f7e1
commit 4fe2b0597d
@@ -17,13 +17,21 @@ pub struct Fedora {
const BINARY: Text = "dnf"; const BINARY: Text = "dnf";
const SECTION: Text = "fedora"; const SECTION: Text = "fedora";
const SWITCHES_INFO: Switches = &[
const SWITCHES_INFO: Switches = &["info"]; const SWITCHES_INFO: Switches = &["info"];
const SWITCHES_INSTALL: Switches = &["install"]; const SWITCHES_INSTALL: Switches = &["install"];
const SWITCHES_MAKE_DEPENDENCY: Switches = &[]; const SWITCHES_MAKE_DEPENDENCY: Switches = &[];
const SWITCHES_NOCONFIRM: Switches = &["--assumeyes"]; const SWITCHES_NOCONFIRM: Switches = &["--assumeyes"];
const SWITCHES_REMOVE: Switches = &["remove"]; const SWITCHES_REMOVE: Switches = &["remove"];
const SWITCHES_FETCH_USER: Switches = &[
"repoquery",
"--userinstalled",
"--queryformat",
"%{from_repo}/%{name}",
];
const SWITCHES_FETCH_GLOBAL: Switches = &[
"repoquery", "repoquery",
"--installed", "--installed",
"--queryformat", "--queryformat",
@@ -39,7 +47,7 @@ impl Backend for Fedora {
fn get_all_installed_packages(&self) -> Result<HashSet<Package>> { fn get_all_installed_packages(&self) -> Result<HashSet<Package>> {
let mut cmd = Command::new(self.get_binary()); let mut cmd = Command::new(self.get_binary());
cmd.args(self.get_switches_info()); cmd.args(SWITCHES_FETCH_GLOBAL);
let output = String::from_utf8(cmd.output()?.stdout)?; let output = String::from_utf8(cmd.output()?.stdout)?;
let packages = output.lines().map(create_package).collect(); let packages = output.lines().map(create_package).collect();
@@ -49,12 +57,7 @@ impl Backend for Fedora {
fn get_explicitly_installed_packages(&self) -> Result<HashSet<Package>> { fn get_explicitly_installed_packages(&self) -> Result<HashSet<Package>> {
let mut cmd = Command::new(self.get_binary()); let mut cmd = Command::new(self.get_binary());
cmd.args([ cmd.args(SWITCHES_FETCH_USER);
"repoquery",
"--userinstalled",
"--queryformat",
"%{from_repo}/%{name}",
]);
let output = String::from_utf8(cmd.output()?.stdout)?; let output = String::from_utf8(cmd.output()?.stdout)?;
let packages = output.lines().map(create_package).collect(); let packages = output.lines().map(create_package).collect();