feat: pure subcommand

This commit is contained in:
2026-05-29 23:51:27 +02:00
parent 95a75dcd76
commit 5a614e366e
3 changed files with 66 additions and 9 deletions
+35 -1
View File
@@ -1,4 +1,4 @@
use crate::{error::Result, world::Packages};
use crate::{PRIVLAGE_ESCELATE_COMMAND, error::Result, world::Packages};
use std::process::{Command, Stdio};
pub fn get_system_state() -> Result<Packages> {
@@ -28,3 +28,37 @@ pub fn get_system_state() -> Result<Packages> {
ignore: Vec::new(),
})
}
pub fn get_unneeded_packages() -> Result<Vec<String>> {
let command = Command::new("pacman")
.arg("-Qqdt")
.stdout(Stdio::piped())
.output()?;
let packages: Vec<String> = String::from_utf8(command.stdout)?
.split_whitespace()
.map(|x| x.to_owned())
.collect();
Ok(packages)
}
pub fn remove_packages(packages: &[String], all: bool) -> Result<()> {
let mut command = Command::new(PRIVLAGE_ESCELATE_COMMAND);
command.arg("pacman");
if all {
command.arg("-Rns");
} else {
command.arg("-Rs");
}
command
.args(packages)
.stdin(Stdio::inherit())
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
.status()?;
Ok(())
}