From dba4ede596a808ea0c30cd6fabf1062f7c09b76b Mon Sep 17 00:00:00 2001 From: michal Date: Thu, 20 Jan 2022 23:23:28 +0000 Subject: [PATCH] finalising some stuff --- src/internal/strings.rs | 10 +++++----- src/operations/aur_install.rs | 2 +- src/operations/install.rs | 32 +++++++++++++++++++------------- 3 files changed, 25 insertions(+), 19 deletions(-) diff --git a/src/internal/strings.rs b/src/internal/strings.rs index a91becc..2850ee8 100644 --- a/src/internal/strings.rs +++ b/src/internal/strings.rs @@ -7,7 +7,7 @@ use std::{env, io}; use crate::uwu; pub fn info(a: String) { - let a = if env::var("AME_UWU").unwrap_or("".to_string()) == "true" { + let a = if env::var("AME_UWU").unwrap_or_else(|_| "".to_string()) == "true" { uwu!(&a) } else { a @@ -17,7 +17,7 @@ pub fn info(a: String) { } pub fn crash(a: String, b: i32) { - let a = if env::var("AME_UWU").unwrap_or("".to_string()) == "true" { + let a = if env::var("AME_UWU").unwrap_or_else(|_| "".to_string()) == "true" { uwu!(&a) } else { a @@ -28,8 +28,8 @@ pub fn crash(a: String, b: i32) { } pub fn log(a: String) { - let a = if env::var("AME_UWU").unwrap_or("".to_string()) == "true" - && env::var("AME_UWU_DEBUG").unwrap_or("".to_string()) == "true" + let a = if env::var("AME_UWU").unwrap_or_else(|_| "".to_string()) == "true" + && env::var("AME_UWU_DEBUG").unwrap_or_else(|_| "".to_string()) == "true" { uwu!(&a) } else { @@ -50,7 +50,7 @@ pub fn prompt(a: String, b: bool) -> bool { let default = ["[Y/n]", "[y/N]"]; let i = if b { 0 } else { 1 }; - let a = if env::var("AME_UWU").unwrap_or("".to_string()) == "true" { + let a = if env::var("AME_UWU").unwrap_or_else(|_| "".to_string()) == "true" { uwu!(&a) } else { a diff --git a/src/operations/aur_install.rs b/src/operations/aur_install.rs index eb124fa..15c0ecc 100644 --- a/src/operations/aur_install.rs +++ b/src/operations/aur_install.rs @@ -85,7 +85,7 @@ pub fn aur_install(a: Vec, options: Options) { if !noconfirm { let p = prompt( - "Would you like to view or edit {}'s PKGBUILD?".to_string(), + format!("Would you like to view or edit {}'s PKGBUILD?", pkg), false, ); let editor = env::var("EDITOR").unwrap_or_else(|_| "nano".parse().unwrap()); diff --git a/src/operations/install.rs b/src/operations/install.rs index 91c7b63..eddf68a 100644 --- a/src/operations/install.rs +++ b/src/operations/install.rs @@ -1,32 +1,38 @@ -use crate::{info, log, Options}; +use crate::{crash, info, log, Options}; -pub fn install(mut a: Vec, options: Options) { +pub fn install(a: Vec, options: Options) { info(format!("Installing packages {} from repos", &a.join(", "))); - let b = a.clone(); + let mut opers = vec![]; if options.noconfirm { - a.push("--noconfirm".to_string()); + opers.push("--noconfirm".to_string()); } if options.asdeps { - a.push("--asdeps".to_string()); + opers.push("--asdeps".to_string()); } let verbosity = options.verbosity; if verbosity >= 1 { - log(format!("Installing from repos: {:?}", &b)); + log(format!("Installing from repos: {:?}", &a)); } let r = runas::Command::new("pacman") .arg("-S") .arg("--needed") .args(&a) + .args(&opers) .status() .expect("Something has gone wrong"); - if let Some(x) = r.code() { - if verbosity >= 1 { - log(format!( - "Installing packages: {:?} exited with code {}", - &b, x - )); - } + if r.code() != Some(0) { + crash( + format!( + "An error occured while installing packages: {}, aborting", + a.join(", ") + ), + 1, + ); + } + + if verbosity >= 1 { + log(format!("Installing packages: {:?} was successful", &a)); } }