builder: Add pacdiff builder

i18n
Fries 2 years ago committed by fries1234
parent 8c35eb1250
commit 07486a5430

@ -1,4 +1,5 @@
pub mod git;
pub mod makepkg;
pub mod pacdiff;
pub mod pacman;
pub mod pager;

@ -0,0 +1,27 @@
use crate::internal::{
commands::{ShellCommand, StringOutput},
error::{AppError, AppResult, SilentUnwrap},
exit_code::AppExitCode,
};
#[derive(Debug, Default)]
pub struct PacdiffBuilder {}
impl PacdiffBuilder {
pub async fn list() -> AppResult<StringOutput> {
let result = ShellCommand::pacdiff()
.args(&["-o", "-f"])
.elevated()
.wait_with_output()
.await?;
if result.status.success() {
Ok(result)
} else {
Err(AppError::Other(result.stderr))
}
}
pub async fn pacdiff() -> AppResult<()> {
ShellCommand::pacdiff().elevated().wait_success().await
}
}

@ -1,5 +1,6 @@
use crossterm::style::Stylize;
use crate::builder::pacdiff::PacdiffBuilder;
use crate::internal::commands::ShellCommand;
use crate::internal::config::Config;
use crate::internal::error::SilentUnwrap;
@ -19,12 +20,7 @@ pub async fn detect() {
let mut pacnew = vec![];
// Run `find` to find pacnew files and split by lines into a vec
let find = ShellCommand::pacdiff()
.args(&["-o", "-f"])
.elevated()
.wait_with_output()
.await
.silent_unwrap(AppExitCode::PacmanError);
let find = PacdiffBuilder::list().await.unwrap();
let find_lines = find.stdout.split('\n');
for line in find_lines {
if !line.is_empty() {
@ -54,18 +50,10 @@ pub async fn detect() {
tracing::warn!("You can surpress this warning in the future by setting `pacdiff_warn` to \"false\" in ~/.config/ame/config.toml");
if prompt!(default no, "Continue?") {
ShellCommand::pacdiff()
.elevated()
.wait()
.await
.silent_unwrap(AppExitCode::PacmanError);
PacdiffBuilder::pacdiff().await.unwrap();
}
} else {
ShellCommand::pacdiff()
.elevated()
.wait()
.await
.silent_unwrap(AppExitCode::PacmanError);
PacdiffBuilder::pacdiff().await.unwrap();
}
}
}

Loading…
Cancel
Save