i18n
jnats 3 years ago
parent 5309d4347a
commit fd6a008efb

@ -1,6 +1,6 @@
[package] [package]
name = "ame" name = "ame"
version = "2.3.1" version = "2.4.0"
authors = [ "jnats <jnats@salyut.one>", "axtlos <axtlos@salyut.one>" ] authors = [ "jnats <jnats@salyut.one>", "axtlos <axtlos@salyut.one>" ]
edition = "2018" edition = "2018"
description = "a fast and efficient aur helper." description = "a fast and efficient aur helper."

@ -1,6 +1,20 @@
mod mods; mod mods;
use mods::{clearcache::clearcache, clone::clone, help::help, install::install, inssort::inssort, search::{a_search, r_search}, uninstall::uninstall, upgrade::upgrade, update::update, ver::ver, strs::inf, strs::err_unrec, strs::err_rec, xargs::*}; use mods::{
clearcache::clearcache,
clone::clone,
help::help,
inssort::inssort,
install::install,
search::{a_search, r_search},
strs::err_rec,
strs::err_unrec,
strs::inf,
uninstall::uninstall,
update::update,
upgrade::upgrade,
ver::ver,
xargs::*,
};
use std::{env, process::exit, process::Command}; use std::{env, process::exit, process::Command};
fn main() { fn main() {
@ -70,11 +84,12 @@ fn main() {
match pass.code() { match pass.code() {
Some(1) => { Some(1) => {
err_rec(format!("No such operation \"{}\"", args.join(" "))); err_rec(format!("No such operation \"{}\"", args.join(" ")));
inf(format!("Try running \"ame help\" for an overview of how to use ame")) inf(format!(
"Try running \"ame help\" for an overview of how to use ame"
))
} }
Some(_) => {} Some(_) => {}
None => { None => err_unrec(format!("Something has gone terribly wrong.")),
err_unrec(format!("Something has gone terribly wrong.")) }
}}
} }
} }

@ -1,12 +1,12 @@
pub mod clearcache; pub mod clearcache;
pub mod clone; pub mod clone;
pub mod help; pub mod help;
pub mod inssort;
pub mod install; pub mod install;
pub mod search; pub mod search;
pub mod strs;
pub mod uninstall; pub mod uninstall;
pub mod upgrade;
pub mod update; pub mod update;
pub mod strs; pub mod upgrade;
pub mod ver; pub mod ver;
pub mod inssort;
pub mod xargs; pub mod xargs;

@ -1,5 +1,5 @@
use std::fs;
use crate::mods::strs::err_rec; use crate::mods::strs::err_rec;
use std::fs;
pub fn clearcache() { pub fn clearcache() {
let path = format!("{}/.cache/ame/", std::env::var("HOME").unwrap()); let path = format!("{}/.cache/ame/", std::env::var("HOME").unwrap());

@ -1,14 +1,21 @@
use crate::{
err_unrec, inf, inssort, mods::strs::prompt, mods::strs::sec, mods::strs::succ,
mods::uninstall::uninstall,
};
use git2::Repository; use git2::Repository;
use moins::Moins; use moins::Moins;
use std::{env, fs, path::Path, process::Command}; use std::{env, fs, path::Path, process::Command};
use crate::{err_unrec, inf, inssort, mods::strs::succ, mods::strs::sec, mods::strs::prompt, mods::uninstall::uninstall};
fn uninstall_make_depend(results: Vec<raur::Package>, pkg: &str) { fn uninstall_make_depend(results: Vec<raur::Package>, pkg: &str) {
let aurpkgname = results[0].name.to_string(); let aurpkgname = results[0].name.to_string();
let make_depends = raur::info(&[&aurpkgname]).unwrap()[0].make_depends.clone(); let make_depends = raur::info(&[&aurpkgname]).unwrap()[0].make_depends.clone();
if make_depends.len() != 0 { if make_depends.len() != 0 {
inf(format!("{} installed following make dependencies: {}", pkg, make_depends.join(", "))); inf(format!(
"{} installed following make dependencies: {}",
pkg,
make_depends.join(", ")
));
let remove = prompt(format!("Would you like to remove them?")); let remove = prompt(format!("Would you like to remove them?"));
if remove == true { if remove == true {
uninstall(true, make_depends); uninstall(true, make_depends);
@ -32,12 +39,9 @@ pub fn clone(noconfirm: bool, pkg: &str) {
if !path.is_dir() { if !path.is_dir() {
let cache_result = fs::create_dir(&path); let cache_result = fs::create_dir(&path);
match cache_result { match cache_result {
Ok(_) => { Ok(_) => inf(format!("Created cache path (first run)")),
inf(format!("Created cache path (first run)")) Err(_) => err_unrec(format!("Could not create cache path")),
} }
Err(_) => {
err_unrec(format!("Could not create cache path"))
}}
} }
inf(format!("Cloning {} ...", pkg)); inf(format!("Cloning {} ...", pkg));
@ -45,31 +49,28 @@ pub fn clone(noconfirm: bool, pkg: &str) {
if Path::new(&pkgdir).is_dir() { if Path::new(&pkgdir).is_dir() {
let rm_result = fs::remove_dir_all(&pkgdir); let rm_result = fs::remove_dir_all(&pkgdir);
match rm_result { match rm_result {
Ok(_) => { Ok(_) => inf(format!(
inf(format!("Package path for {} already found. Removing to reinstall", pkg)) "Package path for {} already found. Removing to reinstall",
pkg
)),
Err(_) => err_unrec(format!(
"Package path for {} already found, but could not remove to reinstall",
pkg
)),
} }
Err(_) => {
err_unrec(format!("Package path for {} already found, but could not remove to reinstall", pkg))
}}
} }
let dir_result = fs::create_dir(&pkgdir); let dir_result = fs::create_dir(&pkgdir);
match dir_result { match dir_result {
Ok(_) => { Ok(_) => inf(format!("Cloned {} to package directory", pkg)),
inf(format!("Cloned {} to package directory", pkg)) Err(_) => err_unrec(format!("Couldn't create package directory for {}", pkg)),
} }
Err(_) => {
err_unrec(format!("Couldn't create package directory for {}", pkg))
}}
let cd_result = env::set_current_dir(&pkgdir); let cd_result = env::set_current_dir(&pkgdir);
match cd_result { match cd_result {
Ok(_) => { Ok(_) => inf(format!("Entered package directory")),
inf(format!("Entered package directory")) Err(_) => err_unrec(format!("Could not enter package directory")),
} }
Err(_) => {
err_unrec(format!("Could not enter package directory"))
}}
sec(format!("Installing AUR package depends")); sec(format!("Installing AUR package depends"));
@ -84,9 +85,8 @@ pub fn clone(noconfirm: bool, pkg: &str) {
Ok(_) => { Ok(_) => {
inf(format!("Cloning {} into package directory", pkg)); inf(format!("Cloning {} into package directory", pkg));
} }
Err(_) => { Err(_) => err_unrec(format!("Failed cloning {} into package directory", pkg)),
err_unrec(format!("Failed cloning {} into package directory", pkg)) }
}}
if noconfirm == false { if noconfirm == false {
let pkgbuild = prompt(format!("View PKGBUILD?")); let pkgbuild = prompt(format!("View PKGBUILD?"));
@ -109,7 +109,8 @@ pub fn clone(noconfirm: bool, pkg: &str) {
} }
Err(_) => { Err(_) => {
err_unrec(format!("Couldn't install {}", pkg)); err_unrec(format!("Couldn't install {}", pkg));
}}; }
};
} else { } else {
sec(format!("Installing {} ...", pkg)); sec(format!("Installing {} ...", pkg));
let install_result = Command::new("makepkg") let install_result = Command::new("makepkg")
@ -125,6 +126,7 @@ pub fn clone(noconfirm: bool, pkg: &str) {
} }
None => { None => {
err_unrec(format!("Couldn't install {}", pkg)); err_unrec(format!("Couldn't install {}", pkg));
}}; }
};
} }
} }

@ -1,9 +1,10 @@
use crate::mods::strs::{inf, err_rec}; use crate::mods::strs::{err_rec, inf};
pub fn help() { pub fn help() {
println!(""); println!("");
inf(format!("Usage:")); inf(format!("Usage:"));
println!(" println!(
"
ame -S(n) / ins <pkg> - install a package ame -S(n) / ins <pkg> - install a package
ame -R(n) / -Rs(n) / rm <pkg> - remove a package ame -R(n) / -Rs(n) / rm <pkg> - remove a package
ame -Syu(n) / upg - upgrade all packages to latest version ame -Syu(n) / upg - upgrade all packages to latest version
@ -12,9 +13,9 @@ ame -Sa / aursea <pkg> - search for a package in the aur
ame -Sr / repsea <pkg> - search for a package in the repos ame -Sr / repsea <pkg> - search for a package in the repos
ame -v / ver - contributors and version info ame -v / ver - contributors and version info
ame <any valid pacman flags> - passes said flags to be processed by pacman"); ame <any valid pacman flags> - passes said flags to be processed by pacman"
);
println!(""); println!("");
err_rec(format!("Appending 'n' where (n) is present passes '--noconfirm' to pacman. Use at your own risk. (alternatively, using '--noconfirm' as a flag works too.)")); err_rec(format!("Appending 'n' where (n) is present passes '--noconfirm' to pacman. Use at your own risk. (alternatively, using '--noconfirm' as a flag works too.)"));
println!(""); println!("");
} }

@ -1,5 +1,5 @@
use crate::{clone, install, err_unrec, mods::strs::sec}; use crate::{clone, err_unrec, install, mods::strs::sec};
use std::process::{Stdio, Command}; use std::process::{Command, Stdio};
pub fn inssort(noconfirm: bool, pkgs: Vec<String>) { pub fn inssort(noconfirm: bool, pkgs: Vec<String>) {
let mut repo = vec![]; let mut repo = vec![];
@ -12,18 +12,12 @@ pub fn inssort(noconfirm: bool, pkgs: Vec<String>) {
.status() .status()
.expect("Something has gone wrong."); .expect("Something has gone wrong.");
match out.code() { match out.code() {
Some(0) => { Some(0) => repo.push(pkg),
repo.push(pkg) Some(1) => aur.push(pkg),
Some(_) => err_unrec(format!("Something has gone terribly wrong")),
None => err_unrec(format!("Process terminated")),
} }
Some(1) => {
aur.push(pkg)
} }
Some(_) => {
err_unrec(format!("Something has gone terribly wrong"))
}
None => {
err_unrec(format!("Process terminated"))
}}}
if repo.len() != 0 { if repo.len() != 0 {
sec(format!("Installing repo packages: {}", &repo.join(", "))); sec(format!("Installing repo packages: {}", &repo.join(", ")));

@ -1,31 +1,30 @@
use runas::Command;
use crate::mods::strs::{err_unrec, succ}; use crate::mods::strs::{err_unrec, succ};
use runas::Command;
pub fn install(noconfirm: bool, pkg: &str) { pub fn install(noconfirm: bool, pkg: &str) {
let pkgs: Vec<&str> = pkg.split(" ").collect(); let pkgs: Vec<&str> = pkg.split(" ").collect();
if noconfirm == true { if noconfirm == true {
let result = Command::new("pacman").arg("-Sy").arg("--noconfirm").args(&pkgs).status().expect("Couldn't call pacman"); let result = Command::new("pacman")
.arg("-Sy")
.arg("--noconfirm")
.args(&pkgs)
.status()
.expect("Couldn't call pacman");
match result.code() { match result.code() {
Some(0) => { Some(0) => succ(format!("Succesfully installed packages: {}", pkg)),
succ(format!("Succesfully installed packages: {}", pkg)) Some(_) => err_unrec(format!("Couldn't install packages: {}", pkg)),
} None => err_unrec(format!("Couldn't install packages: {}", pkg)),
Some(_) => { };
err_unrec(format!("Couldn't install packages: {}", pkg))
}
None => {
err_unrec(format!("Couldn't install packages: {}", pkg))
}};
} else { } else {
let result = Command::new("pacman").arg("-Sy").args(&pkgs).status().expect("Couldn't call pacman"); let result = Command::new("pacman")
.arg("-Sy")
.args(&pkgs)
.status()
.expect("Couldn't call pacman");
match result.code() { match result.code() {
Some(0) => { Some(0) => succ(format!("Succesfully installed packages: {}", pkg)),
succ(format!("Succesfully installed packages: {}", pkg)) Some(_) => err_unrec(format!("Couldn't install packages: {}", pkg)),
} None => err_unrec(format!("Couldn't install packages: {}", pkg)),
Some(_) => { };
err_unrec(format!("Couldn't install packages: {}", pkg))
}
None => {
err_unrec(format!("Couldn't install packages: {}", pkg))
}};
} }
} }

@ -1,6 +1,6 @@
use std::{ops::Deref, process::Command}; use crate::mods::strs::{err_rec, err_unrec, succ};
use ansi_term::Colour; use ansi_term::Colour;
use crate::mods::strs::{err_unrec, err_rec, succ}; use std::{ops::Deref, process::Command};
pub fn a_search(pkg: &str) { pub fn a_search(pkg: &str) {
let results = raur::search(&pkg); let results = raur::search(&pkg);
@ -10,11 +10,13 @@ pub fn a_search(pkg: &str) {
err_rec(format!("No matching AUR packages found")); err_rec(format!("No matching AUR packages found"));
} }
for res in r { for res in r {
println!("{}{} {}\n {}", println!(
"{}{} {}\n {}",
Colour::Cyan.bold().paint("aur/"), Colour::Cyan.bold().paint("aur/"),
Colour::White.bold().paint(&res.name), Colour::White.bold().paint(&res.name),
Colour::Green.bold().paint(&res.version), Colour::Green.bold().paint(&res.version),
Colour::White.paint(res.description.as_ref().map_or("n/a", String::deref))); Colour::White.paint(res.description.as_ref().map_or("n/a", String::deref))
);
} }
} }
} }
@ -26,17 +28,9 @@ pub fn r_search(pkg: &str) {
.status() .status()
.unwrap(); .unwrap();
match result.code() { match result.code() {
Some(0) => { Some(0) => succ(format!("Repo search successful")),
succ(format!("Repo search successful")) Some(1) => err_rec(format!("No matching repo packages found")),
} Some(_) => err_unrec(format!("Someting went terribly wrong")),
Some(1) => { None => err_unrec(format!("Couldn't search pacman repos")),
err_rec(format!("No matching repo packages found")) };
}
Some(_) => {
err_unrec(format!("Someting went terribly wrong"))
}
None => {
err_unrec(format!("Couldn't search pacman repos"))
}};
} }

@ -1,49 +1,59 @@
use ansi_term::Colour; use ansi_term::Colour;
use std::{process, env, io, io::Write}; use std::{env, io, io::Write, process};
use uwuizer::*; use uwuizer::*;
pub fn inf(a: std::string::String){ pub fn inf(a: std::string::String) {
if env::var("AME_UWU").unwrap_or("n/a".to_string()) == "YES" { if env::var("AME_UWU").unwrap_or("n/a".to_string()) == "YES" {
println!("{} {}", println!(
"{} {}",
Colour::Purple.paint("❖"), Colour::Purple.paint("❖"),
Colour::White.paint(uwuize!(&a))); Colour::White.paint(uwuize!(&a))
);
} else { } else {
println!("{} {}", println!("{} {}", Colour::Purple.paint("❖"), Colour::White.paint(a));
Colour::Purple.paint("❖"),
Colour::White.paint(a));
} }
} }
pub fn sec(a: std::string::String){ pub fn sec(a: std::string::String) {
if env::var("AME_UWU").unwrap_or("n/a".to_string()) == "YES" { if env::var("AME_UWU").unwrap_or("n/a".to_string()) == "YES" {
println!("{} {}", println!(
"{} {}",
Colour::Purple.bold().paint("❖"), Colour::Purple.bold().paint("❖"),
Colour::White.bold().paint(uwuize!(&a))); Colour::White.bold().paint(uwuize!(&a))
);
} else { } else {
println!("{} {}", println!(
"{} {}",
Colour::Purple.bold().paint("❖"), Colour::Purple.bold().paint("❖"),
Colour::White.bold().paint(a)); Colour::White.bold().paint(a)
);
} }
} }
pub fn succ(a: std::string::String) { pub fn succ(a: std::string::String) {
if env::var("AME_UWU").unwrap_or("n/a".to_string()) == "YES" { if env::var("AME_UWU").unwrap_or("n/a".to_string()) == "YES" {
println!("{} {}", println!(
"{} {}",
Colour::Green.bold().paint("✓"), Colour::Green.bold().paint("✓"),
Colour::Green.paint(uwuize!(&a))); Colour::Green.paint(uwuize!(&a))
);
} else { } else {
println!("{} {}", println!(
"{} {}",
Colour::Green.bold().paint("✓"), Colour::Green.bold().paint("✓"),
Colour::Green.paint(&a)); Colour::Green.paint(&a)
);
} }
} }
pub fn prompt(a: std::string::String) -> bool { pub fn prompt(a: std::string::String) -> bool {
if env::var("AME_UWU").unwrap_or("n/a".to_string()) == "YES" { if env::var("AME_UWU").unwrap_or("n/a".to_string()) == "YES" {
print!("{} {} {}", print!(
"{} {} {}",
Colour::Purple.bold().paint("❖"), Colour::Purple.bold().paint("❖"),
Colour::White.bold().paint(uwuize!(&a)), Colour::White.bold().paint(uwuize!(&a)),
Colour::White.bold().paint("(Y/n): ")); Colour::White.bold().paint("(Y/n): ")
);
io::stdout().flush().ok().expect("Couldn't flush stdout"); io::stdout().flush().ok().expect("Couldn't flush stdout");
let mut yn: String = String::new(); let mut yn: String = String::new();
let _ = std::io::stdin().read_line(&mut yn); let _ = std::io::stdin().read_line(&mut yn);
@ -53,10 +63,12 @@ pub fn prompt(a: std::string::String) -> bool {
true true
} }
} else { } else {
print!("{} {} {}", print!(
"{} {} {}",
Colour::Purple.bold().paint("❖"), Colour::Purple.bold().paint("❖"),
Colour::White.bold().paint(&a), Colour::White.bold().paint(&a),
Colour::White.bold().paint("(Y/n): ")); Colour::White.bold().paint("(Y/n): ")
);
io::stdout().flush().ok().expect("Couldn't flush stdout"); io::stdout().flush().ok().expect("Couldn't flush stdout");
let mut yn: String = String::new(); let mut yn: String = String::new();
let _ = std::io::stdin().read_line(&mut yn); let _ = std::io::stdin().read_line(&mut yn);
@ -68,31 +80,38 @@ pub fn prompt(a: std::string::String) -> bool {
} }
} }
pub fn err_unrec(a: std::string::String) { pub fn err_unrec(a: std::string::String) {
if env::var("AME_UWU").unwrap_or("n/a".to_string()) == "YES" { if env::var("AME_UWU").unwrap_or("n/a".to_string()) == "YES" {
println!("{} {} {}", println!(
"{} {} {}",
Colour::Red.bold().paint(uwuize!("✖ Unrecoverable error:")), Colour::Red.bold().paint(uwuize!("✖ Unrecoverable error:")),
Colour::Red.paint(uwuize!(&a)), Colour::Red.paint(uwuize!(&a)),
Colour::Red.bold().paint(uwuize!("Terminating."))); Colour::Red.bold().paint(uwuize!("Terminating."))
);
process::exit(1); process::exit(1);
} else { } else {
println!("{} {} {}", println!(
"{} {} {}",
Colour::Red.bold().paint("✖ Unrecoverable error:"), Colour::Red.bold().paint("✖ Unrecoverable error:"),
Colour::Red.paint(a), Colour::Red.paint(a),
Colour::Red.bold().paint("Terminating.")); Colour::Red.bold().paint("Terminating.")
);
process::exit(1); process::exit(1);
} }
} }
pub fn err_rec(a: std::string::String) { pub fn err_rec(a: std::string::String) {
if env::var("AME_UWU").unwrap_or("n/a".to_string()) == "YES" { if env::var("AME_UWU").unwrap_or("n/a".to_string()) == "YES" {
println!("{} {}", println!(
"{} {}",
Colour::Yellow.bold().paint(uwuize!("⚠ WARNING:")), Colour::Yellow.bold().paint(uwuize!("⚠ WARNING:")),
Colour::Yellow.paint(uwuize!(&a))); Colour::Yellow.paint(uwuize!(&a))
);
} else { } else {
println!("{} {}", println!(
"{} {}",
Colour::Yellow.bold().paint("⚠ WARNING:"), Colour::Yellow.bold().paint("⚠ WARNING:"),
Colour::Yellow.paint(a)); Colour::Yellow.paint(a)
);
} }
} }

@ -1,33 +1,41 @@
use crate::mods::strs::{err_rec, err_unrec, sec, succ};
use runas::Command; use runas::Command;
use crate::mods::strs::{err_unrec, sec, succ, err_rec};
use std::{fs, path::Path}; use std::{fs, path::Path};
pub fn uninstall(noconfirm: bool, pkgs: Vec<String>) { pub fn uninstall(noconfirm: bool, pkgs: Vec<String>) {
sec(format!("Attempting to uninstall packages: {}", &pkgs.join(" "))); sec(format!(
"Attempting to uninstall packages: {}",
&pkgs.join(" ")
));
if noconfirm == true { if noconfirm == true {
let result = Command::new("pacman").arg("-Rs").args(&pkgs).arg("--noconfirm").status().expect("Couldn't call pacman"); let result = Command::new("pacman")
.arg("-Rs")
.args(&pkgs)
.arg("--noconfirm")
.status()
.expect("Couldn't call pacman");
match result.code() { match result.code() {
Some(0) => { Some(0) => succ(format!(
succ(format!("Succesfully uninstalled packages: {}", &pkgs.join(" "))) "Succesfully uninstalled packages: {}",
} &pkgs.join(" ")
Some(_) => { )),
err_rec(format!("Couldn't uninstall packages: {}", &pkgs.join(" "))) Some(_) => err_rec(format!("Couldn't uninstall packages: {}", &pkgs.join(" "))),
} None => err_rec(format!("Couldn't uninstall packages: {}", &pkgs.join(" "))),
None =>{ };
err_rec(format!("Couldn't uninstall packages: {}", &pkgs.join(" ")))
}};
} else { } else {
let result = Command::new("pacman").arg("-Rs").args(&pkgs).status().expect("Couldn't call pacman"); let result = Command::new("pacman")
.arg("-Rs")
.args(&pkgs)
.status()
.expect("Couldn't call pacman");
match result.code() { match result.code() {
Some(0) => { Some(0) => succ(format!(
succ(format!("Succesfully uninstalled packages: {}", &pkgs.join(" "))) "Succesfully uninstalled packages: {}",
} &pkgs.join(" ")
Some(_) => { )),
err_rec(format!("Couldn't uninstall packages: {}", &pkgs.join(" "))) Some(_) => err_rec(format!("Couldn't uninstall packages: {}", &pkgs.join(" "))),
} None => err_rec(format!("Couldn't uninstall packages: {}", &pkgs.join(" "))),
None =>{ };
err_rec(format!("Couldn't uninstall packages: {}", &pkgs.join(" ")))
}};
} }
for pkg in &pkgs { for pkg in &pkgs {
let pkgdir = format!("{}/.cache/ame/{}", std::env::var("HOME").unwrap(), pkg); let pkgdir = format!("{}/.cache/ame/{}", std::env::var("HOME").unwrap(), pkg);
@ -35,12 +43,9 @@ pub fn uninstall(noconfirm: bool, pkgs: Vec<String>) {
if path.is_dir() { if path.is_dir() {
let rm_result = fs::remove_dir_all(&path); let rm_result = fs::remove_dir_all(&path);
match rm_result { match rm_result {
Ok(_) => { Ok(_) => succ(format!("Removed AUR cache directory for {}", pkg)),
succ(format!("Removed AUR cache directory for {}", pkg)) Err(_) => err_unrec(format!("Failed to remove AUR cache directory for {}", pkg)),
} };
Err(_) => {
err_unrec(format!("Failed to remove AUR cache directory for {}", pkg))
}};
} }
} }
} }

@ -1,5 +1,5 @@
use runas::Command;
use crate::mods::strs::{err_unrec, sec, succ}; use crate::mods::strs::{err_unrec, sec, succ};
use runas::Command;
pub fn update() { pub fn update() {
sec(format!("Syncing package repos")); sec(format!("Syncing package repos"));
@ -9,13 +9,8 @@ pub fn update() {
.status() .status()
.expect("Couldn't call pacman"); .expect("Couldn't call pacman");
match result.code() { match result.code() {
Some(0) => { Some(0) => succ(format!("Repos succesfully synced")),
succ(format!("Repos succesfully synced")) Some(_) => err_unrec(format!("Couldn't sync package repos")),
} None => err_unrec(format!("Couldn't sync package repos")),
Some(_) => {
err_unrec(format!("Couldn't sync package repos"))
} }
None => {
err_unrec(format!("Couldn't sync package repos"))
}}
} }

@ -1,8 +1,8 @@
use crate::mods::strs::{err_unrec, inf, sec, succ};
use runas::Command; use runas::Command;
use std::env; use std::env;
use crate::mods::strs::{err_unrec, inf, sec, succ};
pub fn upgrade(noconfirm: bool){ pub fn upgrade(noconfirm: bool) {
let homepath = std::env::var("HOME").unwrap(); let homepath = std::env::var("HOME").unwrap();
let cachedir = format!("/{}/.cache/ame/", homepath); let cachedir = format!("/{}/.cache/ame/", homepath);
sec(format!("Performing system upgrade")); sec(format!("Performing system upgrade"));
@ -13,72 +13,63 @@ pub fn upgrade(noconfirm: bool){
.status() .status()
.expect("Couldn't call pacman"); .expect("Couldn't call pacman");
match result.code() { match result.code() {
Some(0) => { Some(0) => succ(format!("All repo packages upgraded")),
succ(format!("All repo packages upgraded")) Some(_) => err_unrec(format!("Couldn't upgrade packages")),
} None => err_unrec(format!("Couldn't upgrade packages")),
Some(_) => { };
err_unrec(format!("Couldn't upgrade packages"))
}
None => {
err_unrec(format!("Couldn't upgrade packages"))
}};
} else { } else {
let result = Command::new("pacman") let result = Command::new("pacman")
.arg("-Syu") .arg("-Syu")
.status() .status()
.expect("Couldn't call pacman"); .expect("Couldn't call pacman");
match result.code() { match result.code() {
Some(0) => { Some(0) => succ(format!("All repo packages upgraded")),
succ(format!("All repo packages upgraded")) Some(_) => err_unrec(format!("Couldn't upgrade packages")),
} None => err_unrec(format!("Couldn't upgrade packages")),
Some(_) => { };
err_unrec(format!("Couldn't upgrade packages"))
}
None => {
err_unrec(format!("Couldn't upgrade packages"))
}};
} }
for file in std::fs::read_dir(&cachedir).unwrap() { for file in std::fs::read_dir(&cachedir).unwrap() {
let dir = &file.unwrap().path(); let dir = &file.unwrap().path();
let output = std::process::Command::new("git").arg("pull").output().unwrap(); let output = std::process::Command::new("git")
.arg("pull")
.output()
.unwrap();
let update_available = String::from_utf8(output.stdout).unwrap(); let update_available = String::from_utf8(output.stdout).unwrap();
let cd_result = env::set_current_dir(&dir); let cd_result = env::set_current_dir(&dir);
match cd_result { match cd_result {
Ok(_) => { Ok(_) => inf(format!("Entered AUR package directory to pull changes")),
inf(format!("Entered AUR package directory to pull changes")) Err(_) => err_unrec(format!(
"Could not enter AUR package directory to pull changes"
)),
} }
Err(_) => {
err_unrec(format!("Could not enter AUR package directory to pull changes"))
}}
if update_available != "Already up to date." { if update_available != "Already up to date." {
let path_as_str = &dir.display().to_string(); let path_as_str = &dir.display().to_string();
let pkg: Vec<&str> = path_as_str.split("/").collect(); let pkg: Vec<&str> = path_as_str.split("/").collect();
inf(format!("{} is up to date", pkg[pkg.len()-1])); inf(format!("{} is up to date", pkg[pkg.len() - 1]));
} else { } else {
let cd2_result = env::set_current_dir(&dir); let cd2_result = env::set_current_dir(&dir);
match cd2_result { match cd2_result {
Ok(_) => { Ok(_) => inf(format!(
inf(format!("Entering AUR package directory to install new version")) "Entering AUR package directory to install new version"
)),
Err(_) => err_unrec(format!(
"Couldn't enter AUR package directory to install new version"
)),
} }
Err(_) => {
err_unrec(format!("Couldn't enter AUR package directory to install new version"))
}}
let makepkg_result = std::process::Command::new("makepkg").arg("-si").status().expect("Couldn't call makepkg"); let makepkg_result = std::process::Command::new("makepkg")
.arg("-si")
.status()
.expect("Couldn't call makepkg");
match makepkg_result.code() { match makepkg_result.code() {
Some(0) => { Some(0) => succ(format!("New AUR package version installed")),
succ(format!("New AUR package version installed")) Some(_) => err_unrec(format!("Couldn't install new AUR package version")),
} None => err_unrec(format!("Couldn't install new AUR package version")),
Some(_) => { };
err_unrec(format!("Couldn't install new AUR package version"))
}
None => {
err_unrec(format!("Couldn't install new AUR package version"))
}};
} }
} }
} }

@ -3,7 +3,7 @@ use ansi_term::Colour;
pub fn ver() { pub fn ver() {
println!(""); println!("");
inf(format!("ame - v2.3.1")); inf(format!("ame - v2.4.0"));
println!(""); println!("");
inf(format!("Contributors:")); inf(format!("Contributors:"));
println!("- axtlos <axtlos@salyut.one>"); println!("- axtlos <axtlos@salyut.one>");
@ -11,9 +11,16 @@ pub fn ver() {
println!("- jasio <jasiobene@icloud.com>"); println!("- jasio <jasiobene@icloud.com>");
println!("- generic <mdc028@bucknell.edu>"); println!("- generic <mdc028@bucknell.edu>");
println!(""); println!("");
inf(format!("This software is licensed under the BSD 3-Clause license.")); inf(format!(
"This software is licensed under the BSD 3-Clause license."
));
inf(format!("All source code is available at:")); inf(format!("All source code is available at:"));
println!(""); println!("");
println!("{}", Colour::Purple.bold().paint("https://github.com/crystal-linux/ame")); println!(
"{}",
Colour::Purple
.bold()
.paint("https://github.com/crystal-linux/ame")
);
println!(""); println!("");
} }

@ -4,7 +4,7 @@ pub fn noconf(args: &Vec<String>) -> bool {
} else { } else {
false false
} }
} }
pub fn argssort(args: &mut Vec<String>) -> &Vec<String> { pub fn argssort(args: &mut Vec<String>) -> &Vec<String> {
if args.contains(&"--noconfirm".to_string()) { if args.contains(&"--noconfirm".to_string()) {
@ -14,4 +14,4 @@ pub fn argssort(args: &mut Vec<String>) -> &Vec<String> {
} else { } else {
args args
} }
} }

Loading…
Cancel
Save