feat: pure subcommand
This commit is contained in:
+35
-1
@@ -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(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user