oh lord - full cargo clippy + fmt

i18n
michal 3 years ago
parent bbec30ead5
commit 5330758ad5

@ -2,48 +2,35 @@ mod mods;
use mods::{ use mods::{
clearcache::clearcache, clearcache::clearcache,
clone::clone, clone::clone,
database::{add_pkg, create_database},
help::help, help::help,
inssort::{ inssort::{inssort, inssort_from_file},
inssort,
inssort_from_file},
install::install, install::install,
purge::{ purge::{purge, purge_from_file},
purge, search::{a_search, r_search},
purge_from_file}, strs::err_rec,
search::{ strs::err_unrec,
a_search, strs::inf,
r_search}, uninstall::{uninstall, uninstall_from_file},
strs::err_rec, update::update,
strs::err_unrec, upgrade::upgrade,
strs::inf, ver::ver,
uninstall::{
uninstall,
uninstall_from_file},
update::update,
upgrade::upgrade,
ver::ver,
xargs::*, xargs::*,
statpkgs::rebuild,
database::{
add_pkg,
create_database,
},
};
use std::{
env,
process::exit
}; };
use std::{env, process::exit};
fn main() { fn main() {
if nix::unistd::Uid::effective().is_root() {
if nix::unistd::Uid::effective().is_root() { // check if user runs ame as root // check if user runs ame as root
err_unrec(format!("Do not run ame as root! this can cause serious damage to your system!")); err_unrec(
"Do not run ame as root! this can cause serious damage to your system!".to_string(),
);
} }
let args: Vec<String> = env::args().skip(1).collect(); let args: Vec<String> = env::args().skip(1).collect();
let mut pkgs: Vec<String> = env::args().skip(2).collect(); let mut pkgs: Vec<String> = env::args().skip(2).collect();
if args.len() <= 0 { if args.is_empty() {
help(); help();
exit(1); exit(1);
} }
@ -57,7 +44,8 @@ fn main() {
let noconfirm: bool = noconf(&args); let noconfirm: bool = noconf(&args);
argssort(&mut pkgs); argssort(&mut pkgs);
match oper.as_str() { // match oper match oper.as_str() {
// match oper
"-S" | "-Sn" | "ins" => { "-S" | "-Sn" | "ins" => {
inssort(noconfirm, false, pkgs); // install inssort(noconfirm, false, pkgs); // install
} }
@ -105,8 +93,9 @@ fn main() {
"-h" | "help" => { "-h" | "help" => {
help(); // help help(); // help
} }
_ => { // if oper is not valid it either passes the args to pacman or prints an error _ => {
let pass = runas::Command::new("pacman") // if oper is not valid it either passes the args to pacman or prints an error
let pass = runas::Command::new("pacman")
.args(&args) .args(&args)
.status() .status()
.expect("Something has gone wrong."); .expect("Something has gone wrong.");
@ -114,12 +103,10 @@ 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!( inf("Try running \"ame help\" for an overview of how to use ame".to_string())
"Try running \"ame help\" for an overview of how to use ame"
))
} }
Some(_) => {} Some(_) => {}
None => err_unrec(format!("Something has gone terribly wrong.")), None => err_unrec("Something has gone terribly wrong.".to_string()),
} }
} }
} }

@ -4,12 +4,12 @@ pub mod database;
pub mod help; pub mod help;
pub mod inssort; pub mod inssort;
pub mod install; pub mod install;
pub mod purge;
pub mod search; pub mod search;
pub mod statpkgs;
pub mod strs; pub mod strs;
pub mod uninstall; pub mod uninstall;
pub mod update; pub mod update;
pub mod upgrade; pub mod upgrade;
pub mod ver; pub mod ver;
pub mod xargs; pub mod xargs;
pub mod purge;
pub mod statpkgs;

@ -1,10 +1,11 @@
use crate::mods::strs::err_rec; use crate::mods::strs::err_rec;
use std::fs; use std::fs;
pub fn clearcache() { // delete all files in cache pub fn clearcache() {
// delete all files in cache
let path = format!("{}/.cache/ame/", std::env::var("HOME").unwrap()); let path = format!("{}/.cache/ame/", std::env::var("HOME").unwrap());
err_rec(format!("Clearing cache")); err_rec("Clearing cache".to_string());
fs::remove_dir_all(&path).unwrap(); fs::remove_dir_all(&path).unwrap();
fs::create_dir(&path).unwrap(); fs::create_dir(&path).unwrap();

@ -1,11 +1,12 @@
use crate::{ use crate::{
err_unrec, inf, inssort, mods::database::add_pkg, mods::strs::prompt, mods::strs::sec, err_unrec, inf, inssort, mods::database::add_pkg, mods::purge::purge, mods::strs::prompt,
mods::strs::succ, mods::purge::purge, mods::strs::sec, mods::strs::succ,
}; };
use moins::Moins; use moins::Moins;
use std::{env, fs, path::Path, process::Command}; use std::{env, fs, path::Path, process::Command};
fn uninstall_make_depend(pkg: &str) { // uninstall make depends of a package fn uninstall_make_depend(pkg: &str) {
// uninstall make depends of a package
let make_depends = raur::info(&[&pkg]).unwrap()[0].make_depends.clone(); let make_depends = raur::info(&[&pkg]).unwrap()[0].make_depends.clone();
let explicit_packages = Command::new("pacman") let explicit_packages = Command::new("pacman")
@ -13,50 +14,45 @@ fn uninstall_make_depend(pkg: &str) { // uninstall make depends of a package
.stdout(std::process::Stdio::piped()) .stdout(std::process::Stdio::piped())
.output() .output()
.expect("Something has gone terribly wrong"); .expect("Something has gone terribly wrong");
let expl_pkgs_parse = String::from_utf8(explicit_packages.stdout).unwrap(); let expl_pkgs_parse = String::from_utf8(explicit_packages.stdout).unwrap();
let expl_pkgs_parse = expl_pkgs_parse.split("\n").collect::<Vec<&str>>(); let expl_pkgs_parse = expl_pkgs_parse.split('\n').collect::<Vec<&str>>();
let mut rem_pkgs = Vec::new(); let mut rem_pkgs = Vec::new();
for pkg in expl_pkgs_parse { for pkg in expl_pkgs_parse {
for i in 0 .. make_depends.len() { #[allow(clippy::needless_range_loop)]
match make_depends[i].contains(pkg) { for i in 0..make_depends.len() {
false => { if let false = make_depends[i].contains(pkg) {
match rem_pkgs.contains(&make_depends[i]) { if let false = rem_pkgs.contains(&make_depends[i]) {
false => { rem_pkgs.push(make_depends[i].as_str().to_string());
rem_pkgs.push(make_depends[i].as_str().to_string());
}
_ => {}
}
} }
_ => {}
}; };
} }
} }
if rem_pkgs.len() != 0 { if !rem_pkgs.is_empty() {
inf(format!( inf(format!(
"{} installed following make dependencies: {}", "{} installed following make dependencies: {}",
pkg, pkg,
rem_pkgs.join(", ") rem_pkgs.join(", ")
)); ));
let remove = prompt(format!("Would you like to remove them?")); let remove = prompt("Would you like to remove them?".to_string());
if remove == true { if remove {
purge(true, rem_pkgs); purge(true, rem_pkgs);
} }
} }
succ(format!("Succesfully installed {}", pkg)); succ(format!("Succesfully installed {}", pkg));
} }
pub fn clone(noconfirm: bool, as_dep: bool, pkg: &str) { // clone a package from aur pub fn clone(noconfirm: bool, as_dep: bool, pkg: &str) {
// clone a package from aur
let cachedir = format!("{}/.cache/ame", env::var("HOME").unwrap()); let cachedir = format!("{}/.cache/ame", env::var("HOME").unwrap());
let path = Path::new(&cachedir); let path = Path::new(&cachedir);
let pkgdir = format!("{}/{}", &cachedir, &pkg); let pkgdir = format!("{}/{}", &cachedir, &pkg);
let package = raur::info(&[pkg]).unwrap(); let package = raur::info(&[pkg]).unwrap();
if package.len() == 0 { if package.is_empty() {
err_unrec(format!("No matching AUR packages found")); err_unrec("No matching AUR packages found".to_string());
} }
let url = format!("https://aur.archlinux.org/{}.git", pkg); let url = format!("https://aur.archlinux.org/{}.git", pkg);
@ -64,8 +60,8 @@ pub fn clone(noconfirm: bool, as_dep: bool, pkg: &str) { // clone a package from
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(_) => inf(format!("Created cache path (first run)")), Ok(_) => inf("Created cache path (first run)".to_string()),
Err(_) => err_unrec(format!("Could not create cache path")), Err(_) => err_unrec("Could not create cache path".to_string()),
} }
} }
@ -93,11 +89,11 @@ pub fn clone(noconfirm: bool, as_dep: bool, pkg: &str) { // clone a package from
let cd_result = env::set_current_dir(&pkgdir); let cd_result = env::set_current_dir(&pkgdir);
match cd_result { match cd_result {
Ok(_) => inf(format!("Entered package directory")), Ok(_) => inf("Entered package directory".to_string()),
Err(_) => err_unrec(format!("Could not enter package directory")), Err(_) => err_unrec("Could not enter package directory".to_string()),
} }
sec(format!("Installing AUR package depends")); sec("Installing AUR package depends".to_string());
inssort(noconfirm, true, package[0].depends.clone()); inssort(noconfirm, true, package[0].depends.clone());
@ -114,18 +110,18 @@ pub fn clone(noconfirm: bool, as_dep: bool, pkg: &str) { // clone a package from
Some(_) => err_unrec(format!("Failed cloning {} into package directory", pkg)), Some(_) => err_unrec(format!("Failed cloning {} into package directory", pkg)),
_ => err_unrec(format!("Failed cloning {} into package directory", pkg)), _ => err_unrec(format!("Failed cloning {} into package directory", pkg)),
} }
if as_dep == false { if !as_dep {
if noconfirm == false { if !noconfirm {
let pkgbuild = prompt(format!("View PKGBUILD?")); let pkgbuild = prompt("View PKGBUILD?".to_string());
if pkgbuild == true { if pkgbuild {
let mut pkgbld = fs::read_to_string(format!("{}/PKGBUILD", &pkgdir)).unwrap(); let mut pkgbld = fs::read_to_string(format!("{}/PKGBUILD", &pkgdir)).unwrap();
Moins::run(&mut pkgbld, None); Moins::run(&mut pkgbld, None);
} }
} }
if noconfirm == true { sec(format!("Installing {} ...", pkg));
sec(format!("Installing {} ...", pkg)); if noconfirm {
let install_result = Command::new("makepkg") let install_result = Command::new("makepkg")
.arg("-si") .arg("-si")
.arg("--noconfirm") .arg("--noconfirm")
@ -141,7 +137,6 @@ pub fn clone(noconfirm: bool, as_dep: bool, pkg: &str) { // clone a package from
} }
}; };
} else { } else {
sec(format!("Installing {} ...", pkg));
let install_result = Command::new("makepkg") let install_result = Command::new("makepkg")
.arg("-si") .arg("-si")
.arg("--needed") .arg("--needed")
@ -162,20 +157,20 @@ pub fn clone(noconfirm: bool, as_dep: bool, pkg: &str) { // clone a package from
} }
} else { } else {
sec(format!("Installing {} ...", pkg)); sec(format!("Installing {} ...", pkg));
let install_result = Command::new("makepkg") let install_result = Command::new("makepkg")
.arg("-si") .arg("-si")
.arg("--noconfirm") .arg("--noconfirm")
.arg("--needed") .arg("--needed")
.arg("--asdeps") .arg("--asdeps")
.status(); .status();
match install_result { match install_result {
Ok(_) => { Ok(_) => {
uninstall_make_depend(pkg); uninstall_make_depend(pkg);
add_pkg(false, pkg); add_pkg(false, pkg);
} }
Err(_) => { Err(_) => {
err_unrec(format!("Couldn't install {}", pkg)); err_unrec(format!("Couldn't install {}", pkg));
} }
}; };
} }
} }

@ -1,27 +1,28 @@
use crate::{err_unrec, inf}; use crate::{err_unrec, inf};
use std::{fs, env}; use std::{env, fs};
pub fn create_database() { pub fn create_database() {
let homepath = env::var("HOME").unwrap(); let homepath = env::var("HOME").unwrap();
let file = format!("{}/.local/share/ame/aur_pkgs.db", env::var("HOME").unwrap()); let file = format!("{}/.local/share/ame/aur_pkgs.db", env::var("HOME").unwrap());
if !std::path::Path::new(&format!("{}/.local/share/ame/", env::var("HOME").unwrap())).is_dir() { if !std::path::Path::new(&format!("{}/.local/share/ame/", env::var("HOME").unwrap())).is_dir() {
let _cdar = fs::create_dir_all(format!("/{}/.local/ame/",homepath)); let _cdar = fs::create_dir_all(format!("/{}/.local/ame/", homepath));
match _cdar { match _cdar {
Ok(_) => { Ok(_) => {
inf(format!("Created path for database (previously missing)")) inf("Created path for database (previously missing)".to_string());
} }
Err(_) => { Err(_) => {
err_unrec(format!("Couldn't create path for database (~/.local/rhare/ame)")) err_unrec("Couldn't create path for database (~/.local/rhare/ame)".to_string())
}
} }
}
} }
let connection = sqlite::open(file).unwrap(); let connection = sqlite::open(file).unwrap();
connection.execute( connection
" .execute(
"
CREATE TABLE pkgs (name TEXT, version TEXT); CREATE TABLE pkgs (name TEXT, version TEXT);
", ",
) )
.unwrap(); .unwrap();
} }
pub fn get_value(pkg: &str, sear_value: &str) -> String { pub fn get_value(pkg: &str, sear_value: &str) -> String {
@ -30,59 +31,56 @@ pub fn get_value(pkg: &str, sear_value: &str) -> String {
let mut return_val = String::new(); let mut return_val = String::new();
match sear_value { match sear_value {
"name" => { "name" => {
let result = connection.iterate(format!("SELECT name FROM pkgs WHERE name = {};",&pkg), |pairs| { let result = connection.iterate(
for &(column, value) in pairs.iter() { format!("SELECT name FROM pkgs WHERE name = {};", &pkg),
return_val = value.unwrap().to_string(); |pairs| {
} for &(_column, value) in pairs.iter() {
true return_val = value.unwrap().to_string();
} }
true
},
); );
match result { match result {
Ok(_) => {} Ok(_) => {}
Err(_) => { Err(_) => err_unrec("Couldn't get value from database".to_string()),
err_unrec(format!("Couldn't get value from database"))
}
} }
}, }
"version" => { "version" => {
let result = connection.iterate(format!("SELECT version FROM pkgs WHERE name = {};",&pkg), |pairs| { let result = connection.iterate(
for &(column, value) in pairs.iter() { format!("SELECT version FROM pkgs WHERE name = {};", &pkg),
return_val = value.unwrap().to_string(); |pairs| {
} for &(_column, value) in pairs.iter() {
true return_val = value.unwrap().to_string();
} }
true
},
); );
match result { match result {
Ok(_) => {} Ok(_) => {}
Err(_) => { Err(_) => err_unrec("Couldn't get value from database".to_string()),
err_unrec(format!("Couldn't get value from database"))
}
} }
}, }
_ => { _ => {
return_val = "error".to_string(); return_val = "error".to_string();
} }
} }
return return_val; return_val
} }
pub fn rem_pkg(pkgs: &Vec<String>) { pub fn rem_pkg(pkgs: &[String]) {
let file = format!("{}/.local/share/ame/aur_pkgs.db", env::var("HOME").unwrap()); let file = format!("{}/.local/share/ame/aur_pkgs.db", env::var("HOME").unwrap());
let connection = sqlite::open(file).unwrap(); let connection = sqlite::open(file).unwrap();
for i in pkgs { for i in pkgs {
let result = connection.execute( let result = connection.execute(format!(
format!(" "
DELETE FROM pkgs WHERE name = {}; DELETE FROM pkgs WHERE name = {};
", i), ",
); i
match result{ ));
Ok(_) => { match result {
inf(format!("Removed {} from database", i)) Ok(_) => inf(format!("Removed {} from database", i)),
} Err(_) => err_unrec(format!("Couldn't remove {} from database", i)),
Err(_) => {
err_unrec(format!("Couldn't remove {} from database", i))
}
} }
} }
} }
@ -97,17 +95,14 @@ pub fn add_pkg(_from_repo: bool, pkg: &str) {
package_name = res[0].name.to_string(); package_name = res[0].name.to_string();
package_version = res[0].version.to_string(); package_version = res[0].version.to_string();
} }
let result = connection.execute( let result = connection.execute(format!(
format!(" "
INSERT INTO pkgs (name, version) VALUES (\"{}\", \"{}\"); INSERT INTO pkgs (name, version) VALUES (\"{}\", \"{}\");
", package_name, package_version), ",
); package_name, package_version
match result{ ));
Ok(_) => { match result {
inf(format!("Added {} to database", package_name)) Ok(_) => inf(format!("Added {} to database", package_name)),
} Err(_) => err_unrec(format!("Couldn't add {} to database", package_name)),
Err(_) => {
err_unrec(format!("Couldn't add {} to database", package_name))
}
} }
} }

@ -1,8 +1,9 @@
use crate::mods::strs::{err_rec, inf}; use crate::mods::strs::{err_rec, inf};
pub fn help() { // print help message pub fn help() {
println!(""); // print help message
inf(format!("Usage:")); println!();
inf("Usage:".to_string());
println!( println!(
" "
ame -S(n) / ins <pkg> - install a package ame -S(n) / ins <pkg> - install a package
@ -17,7 +18,7 @@ ame -h / help - display this help message
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("Appending 'n' where (n) is present passes '--noconfirm' to pacman. Use at your own risk. (alternatively, using '--noconfirm' as a flag works too.)".to_string());
println!(""); println!();
} }

@ -1,35 +1,42 @@
use crate::{clone, err_unrec, install, mods::strs::sec}; use crate::{clone, err_unrec, install, mods::strs::sec};
use std::process::{Command, Stdio};
use regex::Regex; use regex::Regex;
use std::process::{Command, Stdio};
pub fn inssort(noconfirm: bool, as_dep: bool, pkgs: Vec<String>) { // TODO: understand what the fuck is actually going on here pub fn inssort(noconfirm: bool, as_dep: bool, pkgs: Vec<String>) {
// TODO: understand what the fuck is actually going on here
let mut repo = vec![]; let mut repo = vec![];
let mut aur = vec![]; let mut aur = vec![];
let re = Regex::new(r"(\S+)((?:>=|<=)\S+$)").unwrap(); let re = Regex::new(r"(\S+)((?:>=|<=)\S+$)").unwrap();
let reg = Regex::new(r"((?:>=|<=)\S+$)").unwrap(); let reg = Regex::new(r"((?:>=|<=)\S+$)").unwrap();
for pkg in pkgs { for pkg in pkgs {
match pkg.contains("/") { match pkg.contains('/') {
true => { true => match pkg.split('/').collect::<Vec<&str>>()[0] == "aur" {
match pkg.split("/").collect::<Vec<&str>>()[0] == "aur" { true => {
true => { aur.push(pkg.split('/').collect::<Vec<&str>>()[1].to_string());
aur.push(pkg.split("/").collect::<Vec<&str>>()[1].to_string()); }
} false => {
false => { let out = Command::new("bash")
let out = Command::new("bash") .arg("-c")
.arg("-c") .arg(format!(
.arg(format!("pacman -Sl {} | grep {}", pkg.split("/").collect::<Vec<&str>>()[0],pkg.split("/").collect::<Vec<&str>>()[1])) "pacman -Sl {} | grep {}",
.stdout(Stdio::null()) pkg.split('/').collect::<Vec<&str>>()[0],
.status() pkg.split('/').collect::<Vec<&str>>()[1]
.expect("Something has gone wrong."); ))
match out.code() { .stdout(Stdio::null())
Some(0) => repo.push(reg.replace_all(&pkg, "").to_string()), .status()
Some(1) => err_unrec(format!("Package {} not found in repository {}", pkg.split("/").collect::<Vec<&str>>()[1],pkg.split("/").collect::<Vec<&str>>()[0])), .expect("Something has gone wrong.");
Some(_) => err_unrec(format!("Something has gone terribly wrong")), match out.code() {
None => err_unrec(format!("Process terminated")), Some(0) => repo.push(reg.replace_all(&pkg, "").to_string()),
} Some(1) => err_unrec(format!(
"Package {} not found in repository {}",
pkg.split('/').collect::<Vec<&str>>()[1],
pkg.split('/').collect::<Vec<&str>>()[0]
)),
Some(_) => err_unrec("Something has gone terribly wrong".to_string()),
None => err_unrec("Process terminated".to_string()),
} }
} }
} },
false => { false => {
let caps = re.captures(&pkg); let caps = re.captures(&pkg);
match caps { match caps {
@ -46,8 +53,8 @@ pub fn inssort(noconfirm: bool, as_dep: bool, pkgs: Vec<String>) { // TODO: unde
match out.code() { match out.code() {
Some(0) => repo.push(reg.replace_all(&pkg, "").to_string()), Some(0) => repo.push(reg.replace_all(&pkg, "").to_string()),
Some(1) => aur.push(pkg), Some(1) => aur.push(pkg),
Some(_) => err_unrec(format!("Something has gone terribly wrong")), Some(_) => err_unrec("Something has gone terribly wrong".to_string()),
None => err_unrec(format!("Process terminated")), None => err_unrec("Process terminated".to_string()),
} }
} }
None => { None => {
@ -60,16 +67,16 @@ pub fn inssort(noconfirm: bool, as_dep: bool, pkgs: Vec<String>) { // TODO: unde
match out.code() { match out.code() {
Some(0) => repo.push(pkg), Some(0) => repo.push(pkg),
Some(1) => aur.push(pkg), Some(1) => aur.push(pkg),
Some(_) => err_unrec(format!("Something has gone terribly wrong")), Some(_) => err_unrec("Something has gone terribly wrong".to_string()),
None => err_unrec(format!("Process terminated")), None => err_unrec("Process terminated".to_string()),
} }
} }
} }
} }
} }
} }
if as_dep == false { if !as_dep {
if repo.len() != 0 { if !repo.is_empty() {
sec(format!("Installing repo packages: {}", &repo.join(", "))); sec(format!("Installing repo packages: {}", &repo.join(", ")));
install(noconfirm, false, &repo.join(" ")); install(noconfirm, false, &repo.join(" "));
} }
@ -79,9 +86,9 @@ pub fn inssort(noconfirm: bool, as_dep: bool, pkgs: Vec<String>) { // TODO: unde
clone(noconfirm, false, &a); clone(noconfirm, false, &a);
} }
} else { } else {
if repo.len() != 0 { if !repo.is_empty() {
sec(format!("Installing repo packages: {}", &repo.join(", "))); sec(format!("Installing repo packages: {}", &repo.join(", ")));
install(noconfirm, true,&repo.join(" ")); install(noconfirm, true, &repo.join(" "));
} }
for a in aur { for a in aur {
@ -91,7 +98,8 @@ pub fn inssort(noconfirm: bool, as_dep: bool, pkgs: Vec<String>) { // TODO: unde
} }
} }
pub fn inssort_from_file(noconfirm: bool, as_dep: bool, file: &str) { // same thing as above but with a list of packages from a file pub fn inssort_from_file(noconfirm: bool, as_dep: bool, file: &str) {
// same thing as above but with a list of packages from a file
let mut pkgs: Vec<String> = Vec::new(); let mut pkgs: Vec<String> = Vec::new();
let contents = std::fs::read_to_string(&file).expect("Couldn't read file"); let contents = std::fs::read_to_string(&file).expect("Couldn't read file");
for line in contents.lines() { for line in contents.lines() {
@ -102,28 +110,34 @@ pub fn inssort_from_file(noconfirm: bool, as_dep: bool, file: &str) { // same th
let re = Regex::new(r"(\S+)((?:>=|<=)\S+$)").unwrap(); let re = Regex::new(r"(\S+)((?:>=|<=)\S+$)").unwrap();
let reg = Regex::new(r"((?:>=|<=)\S+$)").unwrap(); let reg = Regex::new(r"((?:>=|<=)\S+$)").unwrap();
for pkg in pkgs { for pkg in pkgs {
match pkg.contains("/") { match pkg.contains('/') {
true => { true => match pkg.split('/').collect::<Vec<&str>>()[0] == "aur" {
match pkg.split("/").collect::<Vec<&str>>()[0] == "aur" { true => {
true => { aur.push(pkg.split('/').collect::<Vec<&str>>()[1].to_string());
aur.push(pkg.split("/").collect::<Vec<&str>>()[1].to_string()); }
} false => {
false => { let out = Command::new("bash")
let out = Command::new("bash") .arg("-c")
.arg("-c") .arg(format!(
.arg(format!("pacman -Sl {} | grep {}", pkg.split("/").collect::<Vec<&str>>()[0],pkg.split("/").collect::<Vec<&str>>()[1])) "pacman -Sl {} | grep {}",
.stdout(Stdio::null()) pkg.split('/').collect::<Vec<&str>>()[0],
.status() pkg.split('/').collect::<Vec<&str>>()[1]
.expect("Something has gone wrong."); ))
match out.code() { .stdout(Stdio::null())
Some(0) => repo.push(reg.replace_all(&pkg, "").to_string()), .status()
Some(1) => err_unrec(format!("Package {} not found in repository {}", pkg.split("/").collect::<Vec<&str>>()[1],pkg.split("/").collect::<Vec<&str>>()[0])), .expect("Something has gone wrong.");
Some(_) => err_unrec(format!("Something has gone terribly wrong")), match out.code() {
None => err_unrec(format!("Process terminated")), Some(0) => repo.push(reg.replace_all(&pkg, "").to_string()),
} Some(1) => err_unrec(format!(
"Package {} not found in repository {}",
pkg.split('/').collect::<Vec<&str>>()[1],
pkg.split('/').collect::<Vec<&str>>()[0]
)),
Some(_) => err_unrec("Something has gone terribly wrong".to_string()),
None => err_unrec("Process terminated".to_string()),
} }
} }
} },
false => { false => {
let caps = re.captures(&pkg); let caps = re.captures(&pkg);
match caps { match caps {
@ -140,8 +154,8 @@ pub fn inssort_from_file(noconfirm: bool, as_dep: bool, file: &str) { // same th
match out.code() { match out.code() {
Some(0) => repo.push(reg.replace_all(&pkg, "").to_string()), Some(0) => repo.push(reg.replace_all(&pkg, "").to_string()),
Some(1) => aur.push(pkg), Some(1) => aur.push(pkg),
Some(_) => err_unrec(format!("Something has gone terribly wrong")), Some(_) => err_unrec("Something has gone terribly wrong".to_string()),
None => err_unrec(format!("Process terminated")), None => err_unrec("Process terminated".to_string()),
} }
} }
None => { None => {
@ -154,16 +168,16 @@ pub fn inssort_from_file(noconfirm: bool, as_dep: bool, file: &str) { // same th
match out.code() { match out.code() {
Some(0) => repo.push(pkg), Some(0) => repo.push(pkg),
Some(1) => aur.push(pkg), Some(1) => aur.push(pkg),
Some(_) => err_unrec(format!("Something has gone terribly wrong")), Some(_) => err_unrec("Something has gone terribly wrong".to_string()),
None => err_unrec(format!("Process terminated")), None => err_unrec("Process terminated".to_string()),
} }
} }
} }
} }
} }
} }
if as_dep == false { if !as_dep {
if repo.len() != 0 { if !repo.is_empty() {
sec(format!("Installing repo packages: {}", &repo.join(", "))); sec(format!("Installing repo packages: {}", &repo.join(", ")));
install(noconfirm, false, &repo.join(" ")); install(noconfirm, false, &repo.join(" "));
} }
@ -173,9 +187,9 @@ pub fn inssort_from_file(noconfirm: bool, as_dep: bool, file: &str) { // same th
clone(noconfirm, false, &a); clone(noconfirm, false, &a);
} }
} else { } else {
if repo.len() != 0 { if !repo.is_empty() {
sec(format!("Installing repo packages: {}", &repo.join(", "))); sec(format!("Installing repo packages: {}", &repo.join(", ")));
install(noconfirm, true,&repo.join(" ")); install(noconfirm, true, &repo.join(" "));
} }
for a in aur { for a in aur {
@ -183,4 +197,4 @@ pub fn inssort_from_file(noconfirm: bool, as_dep: bool, file: &str) { // same th
clone(noconfirm, true, &a); clone(noconfirm, true, &a);
} }
} }
} }

@ -1,10 +1,11 @@
use crate::mods::strs::{err_unrec, succ}; use crate::mods::strs::{err_unrec, succ};
use runas::Command; use runas::Command;
pub fn install(noconfirm: bool, as_dep: bool, pkg: &str) { // install a package pub fn install(noconfirm: bool, as_dep: bool, pkg: &str) {
let pkgs: Vec<&str> = pkg.split(" ").collect(); // install a package
if as_dep == false { let pkgs: Vec<&str> = pkg.split(' ').collect();
if noconfirm == true { if !as_dep {
if noconfirm {
let result = Command::new("pacman") let result = Command::new("pacman")
.arg("-S") .arg("-S")
.arg("--noconfirm") .arg("--noconfirm")
@ -45,4 +46,4 @@ pub fn install(noconfirm: bool, as_dep: bool, pkg: &str) { // install a package
None => err_unrec(format!("Couldn't install packages: {}", pkg)), None => err_unrec(format!("Couldn't install packages: {}", pkg)),
}; };
} }
} }

@ -1,120 +1,121 @@
use crate::mods::{ use crate::mods::{
database::rem_pkg, database::rem_pkg,
strs::{err_rec, err_unrec, sec, succ}, strs::{err_rec, err_unrec, sec, succ},
}; };
use runas::Command; use runas::Command;
use std::{fs, path::Path}; use std::{fs, path::Path};
pub fn purge(noconfirm: bool, pkgs: Vec<String>) { // purge packages pub fn purge(noconfirm: bool, pkgs: Vec<String>) {
sec(format!( // purge packages
"Attempting to uninstall packages: {}", sec(format!(
&pkgs.join(" ") "Attempting to uninstall packages: {}",
)); &pkgs.join(" ")
if noconfirm == true { ));
let result = Command::new("pacman") if noconfirm {
.arg("-Rsu") let result = Command::new("pacman")
.args(&pkgs) .arg("-Rsu")
.arg("--noconfirm") .args(&pkgs)
.status() .arg("--noconfirm")
.expect("Couldn't call pacman"); .status()
match result.code() { .expect("Couldn't call pacman");
Some(0) => { match result.code() {
succ(format!( Some(0) => {
"Succesfully uninstalled packages: {}", succ(format!(
&pkgs.join(" ") "Succesfully uninstalled packages: {}",
)); &pkgs.join(" ")
rem_pkg(&pkgs); ));
} rem_pkg(&pkgs);
Some(_) => err_rec(format!("Couldn't uninstall packages: {}", &pkgs.join(" "))), }
None => 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(" "))),
} else { };
let result = Command::new("pacman") } else {
.arg("-Rsu") let result = Command::new("pacman")
.args(&pkgs) .arg("-Rsu")
.status() .args(&pkgs)
.expect("Couldn't call pacman"); .status()
match result.code() { .expect("Couldn't call pacman");
Some(0) => { match result.code() {
succ(format!( Some(0) => {
"Succesfully uninstalled packages: {}", succ(format!(
&pkgs.join(" ") "Succesfully uninstalled packages: {}",
)); &pkgs.join(" ")
rem_pkg(&pkgs); ));
} rem_pkg(&pkgs);
Some(_) => err_rec(format!("Couldn't uninstall packages: {}", &pkgs.join(" "))), }
None => 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(" "))),
} };
for pkg in &pkgs { }
let pkgdir = format!("{}/.cache/ame/{}", std::env::var("HOME").unwrap(), pkg); for pkg in &pkgs {
let path = Path::new(&pkgdir); let pkgdir = format!("{}/.cache/ame/{}", std::env::var("HOME").unwrap(), pkg);
if path.is_dir() { let path = Path::new(&pkgdir);
let rm_result = fs::remove_dir_all(&path); if path.is_dir() {
match rm_result { let rm_result = fs::remove_dir_all(&path);
Ok(_) => succ(format!("Removed AUR cache directory for {}", pkg)), match rm_result {
Err(_) => err_unrec(format!("Failed to remove AUR cache directory for {}", pkg)), Ok(_) => succ(format!("Removed AUR cache directory for {}", pkg)),
}; Err(_) => err_unrec(format!("Failed to remove AUR cache directory for {}", pkg)),
} };
} }
} }
}
pub fn purge_from_file(noconfirm: bool, file: &str) { // purge packages from list of packages pub fn purge_from_file(noconfirm: bool, file: &str) {
let mut pkgs: Vec<String> = Vec::new(); // purge packages from list of packages
let contents = std::fs::read_to_string(&file).expect("Couldn't read file"); let mut pkgs: Vec<String> = Vec::new();
for line in contents.lines() { let contents = std::fs::read_to_string(&file).expect("Couldn't read file");
pkgs.push(line.to_string()); for line in contents.lines() {
} pkgs.push(line.to_string());
sec(format!( }
"Attempting to uninstall packages: {}", sec(format!(
&pkgs.join(" ") "Attempting to uninstall packages: {}",
)); &pkgs.join(" ")
if noconfirm == true { ));
let result = Command::new("pacman") if noconfirm {
.arg("-Rsu") let result = Command::new("pacman")
.args(&pkgs) .arg("-Rsu")
.arg("--noconfirm") .args(&pkgs)
.status() .arg("--noconfirm")
.expect("Couldn't call pacman"); .status()
match result.code() { .expect("Couldn't call pacman");
Some(0) => { match result.code() {
succ(format!( Some(0) => {
"Succesfully uninstalled packages: {}", succ(format!(
&pkgs.join(" ") "Succesfully uninstalled packages: {}",
)); &pkgs.join(" ")
rem_pkg(&pkgs); ));
} rem_pkg(&pkgs);
Some(_) => err_rec(format!("Couldn't uninstall packages: {}", &pkgs.join(" "))), }
None => 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(" "))),
} else { };
let result = Command::new("pacman") } else {
.arg("-Rsu") let result = Command::new("pacman")
.args(&pkgs) .arg("-Rsu")
.status() .args(&pkgs)
.expect("Couldn't call pacman"); .status()
match result.code() { .expect("Couldn't call pacman");
Some(0) => { match result.code() {
succ(format!( Some(0) => {
"Succesfully uninstalled packages: {}", succ(format!(
&pkgs.join(" ") "Succesfully uninstalled packages: {}",
)); &pkgs.join(" ")
rem_pkg(&pkgs); ));
} rem_pkg(&pkgs);
Some(_) => err_rec(format!("Couldn't uninstall packages: {}", &pkgs.join(" "))), }
None => 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(" "))),
} };
for pkg in &pkgs { }
let pkgdir = format!("{}/.cache/ame/{}", std::env::var("HOME").unwrap(), pkg); for pkg in &pkgs {
let path = Path::new(&pkgdir); let pkgdir = format!("{}/.cache/ame/{}", std::env::var("HOME").unwrap(), pkg);
if path.is_dir() { let path = Path::new(&pkgdir);
let rm_result = fs::remove_dir_all(&path); if path.is_dir() {
match rm_result { let rm_result = fs::remove_dir_all(&path);
Ok(_) => succ(format!("Removed AUR cache directory for {}", pkg)), match rm_result {
Err(_) => err_unrec(format!("Failed to remove AUR cache directory for {}", pkg)), Ok(_) => succ(format!("Removed AUR cache directory for {}", pkg)),
}; Err(_) => err_unrec(format!("Failed to remove AUR cache directory for {}", pkg)),
} };
} }
} }
}

@ -2,12 +2,13 @@ use crate::mods::strs::{err_rec, err_unrec, succ};
use ansi_term::Colour; use ansi_term::Colour;
use std::{ops::Deref, process::Command}; use std::{ops::Deref, process::Command};
pub fn a_search(pkg: &str) { // search for a package in the AUR pub fn a_search(pkg: &str) {
// search for a package in the AUR
let results = raur::search(&pkg); let results = raur::search(&pkg);
for r in &results { for r in &results {
if r.len() == 0 { if r.is_empty() {
err_rec(format!("No matching AUR packages found")); err_rec("No matching AUR packages found".to_string());
} }
for res in r { for res in r {
println!( println!(
@ -21,16 +22,17 @@ pub fn a_search(pkg: &str) { // search for a package in the AUR
} }
} }
pub fn r_search(pkg: &str) { // search for a package in the repositories pub fn r_search(pkg: &str) {
// search for a package in the repositories
let result = Command::new("pacman") let result = Command::new("pacman")
.arg("-Ss") .arg("-Ss")
.arg(&pkg) .arg(&pkg)
.status() .status()
.unwrap(); .unwrap();
match result.code() { match result.code() {
Some(0) => succ(format!("Repo search successful")), Some(0) => succ("Repo search successful".to_string()),
Some(1) => err_rec(format!("No matching repo packages found")), Some(1) => err_rec("No matching repo packages found".to_string()),
Some(_) => err_unrec(format!("Someting went terribly wrong")), Some(_) => err_unrec("Someting went terribly wrong".to_string()),
None => err_unrec(format!("Couldn't search pacman repos")), None => err_unrec("Couldn't search pacman repos".to_string()),
}; };
} }

@ -1,3 +1,3 @@
pub fn rebuild(noconfirm: bool) { pub fn rebuild(noconfirm: bool) {
print!("installing crystal config") print!("installing crystal config")
} }

@ -2,8 +2,9 @@ use ansi_term::Colour;
use std::{env, io, io::Write, process, string}; use std::{env, io, io::Write, process, string};
use uwuizer::*; use uwuizer::*;
pub fn inf(a: string::String) { // info pub fn inf(a: string::String) {
if env::var("AME_UWU").unwrap_or("n/a".to_string()) == "YES" { // info
if env::var("AME_UWU").unwrap_or_else(|_| "n/a".to_string()) == "YES" {
println!( println!(
"{} {}", "{} {}",
Colour::Purple.paint("❖"), Colour::Purple.paint("❖"),
@ -14,8 +15,8 @@ pub fn inf(a: string::String) { // info
} }
} }
pub fn sec(a: string::String) { pub fn sec(a: string::String) {
if env::var("AME_UWU").unwrap_or("n/a".to_string()) == "YES" { if env::var("AME_UWU").unwrap_or_else(|_| "n/a".to_string()) == "YES" {
println!( println!(
"{} {}", "{} {}",
Colour::Purple.bold().paint("❖"), Colour::Purple.bold().paint("❖"),
@ -30,8 +31,9 @@ pub fn sec(a: string::String) {
} }
} }
pub fn succ(a: string::String) { // success pub fn succ(a: string::String) {
if env::var("AME_UWU").unwrap_or("n/a".to_string()) == "YES" { // success
if env::var("AME_UWU").unwrap_or_else(|_| "n/a".to_string()) == "YES" {
println!( println!(
"{} {}", "{} {}",
Colour::Green.bold().paint("✓"), Colour::Green.bold().paint("✓"),
@ -46,22 +48,15 @@ pub fn succ(a: string::String) { // success
} }
} }
pub fn prompt(a: string::String) -> bool { // prompt pub fn prompt(a: string::String) -> bool {
if env::var("AME_UWU").unwrap_or("n/a".to_string()) == "YES" { // prompt
if env::var("AME_UWU").unwrap_or_else(|_| "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");
let mut yn: String = String::new();
let _ = std::io::stdin().read_line(&mut yn);
if yn.trim() == "n" || yn.trim() == "N" || yn.trim() == "no" || yn.trim() == "No" {
false
} else {
true
}
} else { } else {
print!( print!(
"{} {} {}", "{} {} {}",
@ -69,26 +64,22 @@ pub fn prompt(a: string::String) -> bool { // prompt
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");
let mut yn: String = String::new();
let _ = std::io::stdin().read_line(&mut yn);
if yn.trim() == "n" || yn.trim() == "N" || yn.trim() == "no" || yn.trim() == "No" {
false
} else {
true
}
} }
io::stdout().flush().ok();
let mut yn: String = String::new();
let _ = std::io::stdin().read_line(&mut yn);
!(yn.trim() == "n" || yn.trim() == "N" || yn.trim() == "no" || yn.trim() == "No")
} }
pub fn err_unrec(a: string::String) { // unrecoverable error pub fn err_unrec(a: string::String) {
if env::var("AME_UWU").unwrap_or("n/a".to_string()) == "YES" { // unrecoverable error
if env::var("AME_UWU").unwrap_or_else(|_| "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);
} else { } else {
println!( println!(
"{} {} {}", "{} {} {}",
@ -96,12 +87,13 @@ pub fn err_unrec(a: string::String) { // 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: string::String) { // recoverable error pub fn err_rec(a: string::String) {
if env::var("AME_UWU").unwrap_or("n/a".to_string()) == "YES" { // recoverable error
if env::var("AME_UWU").unwrap_or_else(|_| "n/a".to_string()) == "YES" {
println!( println!(
"{} {}", "{} {}",
Colour::Yellow.bold().paint(uwuize!("⚠ WARNING:")), Colour::Yellow.bold().paint(uwuize!("⚠ WARNING:")),

@ -5,12 +5,13 @@ use crate::mods::{
use runas::Command; use runas::Command;
use std::{fs, path::Path}; use std::{fs, path::Path};
pub fn uninstall(noconfirm: bool, pkgs: Vec<String>) { // uninstall a package pub fn uninstall(noconfirm: bool, pkgs: Vec<String>) {
// uninstall a package
sec(format!( sec(format!(
"Attempting to uninstall packages: {}", "Attempting to uninstall packages: {}",
&pkgs.join(" ") &pkgs.join(" ")
)); ));
if noconfirm == true { if noconfirm {
let result = Command::new("pacman") let result = Command::new("pacman")
.arg("-Ru") .arg("-Ru")
.args(&pkgs) .args(&pkgs)
@ -59,7 +60,8 @@ pub fn uninstall(noconfirm: bool, pkgs: Vec<String>) { // uninstall a package
} }
} }
pub fn uninstall_from_file(noconfirm: bool, file: &str) { // uninstall a package from a list of packages pub fn uninstall_from_file(noconfirm: bool, file: &str) {
// uninstall a package from a list of packages
let mut pkgs: Vec<String> = Vec::new(); let mut pkgs: Vec<String> = Vec::new();
let contents = std::fs::read_to_string(&file).expect("Couldn't read file"); let contents = std::fs::read_to_string(&file).expect("Couldn't read file");
for line in contents.lines() { for line in contents.lines() {
@ -69,7 +71,7 @@ pub fn uninstall_from_file(noconfirm: bool, file: &str) { // uninstall a package
"Attempting to uninstall packages: {}", "Attempting to uninstall packages: {}",
&pkgs.join(" ") &pkgs.join(" ")
)); ));
if noconfirm == true { if noconfirm {
let result = Command::new("pacman") let result = Command::new("pacman")
.arg("-Ru") .arg("-Ru")
.args(&pkgs) .args(&pkgs)
@ -116,4 +118,4 @@ pub fn uninstall_from_file(noconfirm: bool, file: &str) { // uninstall a package
}; };
} }
} }
} }

@ -1,16 +1,17 @@
use crate::mods::strs::{err_unrec, sec, succ}; use crate::mods::strs::{err_unrec, sec, succ};
use runas::Command; use runas::Command;
pub fn update() { // update the repositories pub fn update() {
sec(format!("Syncing package repos")); // update the repositories
sec("Syncing package repos".to_string());
let result = Command::new("pacman") let result = Command::new("pacman")
.arg("-Sy") .arg("-Sy")
.status() .status()
.expect("Couldn't call pacman"); .expect("Couldn't call pacman");
match result.code() { match result.code() {
Some(0) => succ(format!("Repos succesfully synced")), Some(0) => succ("Repos succesfully synced".to_string()),
Some(_) => err_unrec(format!("Couldn't sync package repos")), Some(_) => err_unrec("Couldn't sync package repos".to_string()),
None => err_unrec(format!("Couldn't sync package repos")), None => err_unrec("Couldn't sync package repos".to_string()),
} }
} }

@ -1,28 +1,31 @@
use crate::{ use crate::{
err_rec, err_unrec, inf, inssort, mods::strs::prompt, mods::strs::sec, mods::strs::succ, uninstall, mods::database::get_value, err_rec, err_unrec, inf, inssort, mods::database::get_value, mods::strs::prompt,
mods::strs::sec, mods::strs::succ, uninstall,
}; };
use runas::Command; use runas::Command;
use std::{env, fs, path::Path}; use std::{env, fs, path::Path};
use toml; use toml;
fn uninstall_make_depend(pkg: &str) { // uninstall make depends installed by ame itself fn uninstall_make_depend(pkg: &str) {
// uninstall make depends installed by ame itself
let make_depends = raur::info(&[&pkg]).unwrap()[0].make_depends.clone(); let make_depends = raur::info(&[&pkg]).unwrap()[0].make_depends.clone();
if make_depends.len() != 0 { if !make_depends.is_empty() {
inf(format!( inf(format!(
"{} installed following make dependencies: {}", "{} installed following make dependencies: {}",
pkg, pkg,
make_depends.join(", ") make_depends.join(", ")
)); ));
let remove = prompt(format!("Would you like to remove them?")); let remove = prompt("Would you like to remove them?".to_string());
if remove == true { if remove {
uninstall(true, make_depends); uninstall(true, make_depends);
} }
} }
succ(format!("Succesfully upgraded {}", pkg)); succ(format!("Succesfully upgraded {}", pkg));
} }
pub fn upgrade(noconfirm: bool) { // upgrade all packages pub fn upgrade(noconfirm: bool) {
// upgrade all packages
let homepath = env::var("HOME").unwrap(); let homepath = env::var("HOME").unwrap();
let cachedir = format!("/{}/.cache/ame/", homepath); let cachedir = format!("/{}/.cache/ame/", homepath);
let cache_exists = Path::new(&format!("/{}/.cache/ame/", homepath)).is_dir(); let cache_exists = Path::new(&format!("/{}/.cache/ame/", homepath)).is_dir();
@ -33,12 +36,8 @@ pub fn upgrade(noconfirm: bool) { // upgrade all packages
} else { } else {
let _cdar = fs::create_dir_all(format!("/{}/.local/ame/", homepath)); let _cdar = fs::create_dir_all(format!("/{}/.local/ame/", homepath));
match _cdar { match _cdar {
Ok(_) => { Ok(_) => inf("Created cache directory (previously missing)".to_string()),
inf(format!("Created cache directory (previously missing)")) Err(_) => err_unrec("Couldn't create cache directory".to_string()),
}
Err(_) => {
err_unrec(format!("Couldn't create cache directory"))
}
} }
err_rec(String::from("Database wasn't found, creating new one")); err_rec(String::from("Database wasn't found, creating new one"));
let _dbfile = fs::File::create(&file); let _dbfile = fs::File::create(&file);
@ -46,24 +45,24 @@ pub fn upgrade(noconfirm: bool) { // upgrade all packages
} }
let db_parsed = database.parse::<toml::Value>().expect("Invalid Database"); let db_parsed = database.parse::<toml::Value>().expect("Invalid Database");
if cache_exists == false { if !cache_exists {
let cachecreate = fs::create_dir_all(&cachedir); let cachecreate = fs::create_dir_all(&cachedir);
match cachecreate { match cachecreate {
Ok(_) => inf(format!("Creating cachedir. (didn't exist previously)")), Ok(_) => inf("Creating cachedir. (didn't exist previously)".to_string()),
Err(_) => err_unrec(format!("Couldn't create cachedir")), Err(_) => err_unrec("Couldn't create cachedir".to_string()),
} }
} }
sec(format!("Performing system upgrade")); sec("Performing system upgrade".to_string());
if noconfirm == true { if noconfirm {
let result = Command::new("pacman") let result = Command::new("pacman")
.arg("-Syu") .arg("-Syu")
.arg("--noconfirm") .arg("--noconfirm")
.status() .status()
.expect("Couldn't call pacman"); .expect("Couldn't call pacman");
match result.code() { match result.code() {
Some(0) => succ(format!("All repo packages upgraded")), Some(0) => succ("All repo packages upgraded".to_string()),
Some(_) => err_unrec(format!("Couldn't upgrade packages")), Some(_) => err_unrec("Couldn't upgrade packages".to_string()),
None => err_unrec(format!("Couldn't upgrade packages")), None => err_unrec("Couldn't upgrade packages".to_string()),
}; };
} else { } else {
let result = Command::new("pacman") let result = Command::new("pacman")
@ -71,28 +70,28 @@ pub fn upgrade(noconfirm: bool) { // upgrade all packages
.status() .status()
.expect("Couldn't call pacman"); .expect("Couldn't call pacman");
match result.code() { match result.code() {
Some(0) => succ(format!("All repo packages upgraded")), Some(0) => succ("All repo packages upgraded".to_string()),
Some(_) => err_unrec(format!("Couldn't upgrade packages")), Some(_) => err_unrec("Couldn't upgrade packages".to_string()),
None => err_unrec(format!("Couldn't upgrade packages")), None => err_unrec("Couldn't upgrade packages".to_string()),
}; };
} }
for entry in db_parsed.as_table() { if let Some(entry) = db_parsed.as_table() {
for (key, _value) in &*entry { for (key, _value) in &*entry {
let results = raur::search(format!("{}", key)); let results = raur::search(key.to_string());
for res in results { if let Ok(res) = results {
let url = format!("https://aur.archlinux.org/{}.git", key); let url = format!("https://aur.archlinux.org/{}.git", key);
let package = raur::info(&[key]).unwrap(); let package = raur::info(&[key]).unwrap();
let version = get_value(&key, "version"); let version = get_value(key, "version");
if res[0].version.contains(&version) { if res[0].version.contains(&version) {
let keydir = format!("{}{}", &cachedir, &key); let keydir = format!("{}{}", &cachedir, &key);
if Path::new(&keydir).is_dir() { if Path::new(&keydir).is_dir() {
let cd_result = env::set_current_dir(&keydir); let cd_result = env::set_current_dir(&keydir);
match cd_result { match cd_result {
Ok(_) => inf(format!("Entered package directory")), Ok(_) => inf("Entered package directory".to_string()),
Err(_) => err_unrec(format!("Could not enter package directory")), Err(_) => err_unrec("Could not enter package directory".to_string()),
} }
inssort(true, true,package[0].depends.clone()); inssort(true, true, package[0].depends.clone());
sec(format!("Installing {} ...", &key)); sec(format!("Installing {} ...", &key));
let install_result = std::process::Command::new("makepkg") let install_result = std::process::Command::new("makepkg")
@ -102,7 +101,7 @@ pub fn upgrade(noconfirm: bool) { // upgrade all packages
.status(); .status();
match install_result { match install_result {
Ok(_) => { Ok(_) => {
uninstall_make_depend(&key); uninstall_make_depend(key);
} }
Err(_) => { Err(_) => {
err_unrec(format!("Couldn't install {}", &key)); err_unrec(format!("Couldn't install {}", &key));
@ -117,7 +116,7 @@ pub fn upgrade(noconfirm: bool) { // upgrade all packages
.expect("Couldn't call makepkg"); .expect("Couldn't call makepkg");
match install_result.code() { match install_result.code() {
Some(0) => { Some(0) => {
uninstall_make_depend(&key); uninstall_make_depend(key);
} }
Some(_) => { Some(_) => {
err_unrec(format!("Couldn't install {}", &key)); err_unrec(format!("Couldn't install {}", &key));
@ -153,8 +152,8 @@ pub fn upgrade(noconfirm: bool) { // upgrade all packages
let cd_result = env::set_current_dir(&keydir); let cd_result = env::set_current_dir(&keydir);
match cd_result { match cd_result {
Ok(_) => inf(format!("Entered package directory")), Ok(_) => inf("Entered package directory".to_string()),
Err(_) => err_unrec(format!("Could not enter package directory")), Err(_) => err_unrec("Could not enter package directory".to_string()),
} }
inssort(true, true, package[0].depends.clone()); inssort(true, true, package[0].depends.clone());
@ -169,8 +168,12 @@ pub fn upgrade(noconfirm: bool) { // upgrade all packages
Some(0) => { Some(0) => {
inf(format!("Cloning {} into package directory", &key)); inf(format!("Cloning {} into package directory", &key));
} }
Some(_) => err_unrec(format!("Failed cloning {} into package directory", &key)), Some(_) => {
_ => err_unrec(format!("Failed cloning {} into package directory", &key)), err_unrec(format!("Failed cloning {} into package directory", &key))
}
_ => {
err_unrec(format!("Failed cloning {} into package directory", &key))
}
} }
} }
@ -182,7 +185,7 @@ pub fn upgrade(noconfirm: bool) { // upgrade all packages
.status(); .status();
match install_result { match install_result {
Ok(_) => { Ok(_) => {
uninstall_make_depend(&key); uninstall_make_depend(key);
} }
Err(_) => { Err(_) => {
err_unrec(format!("Couldn't install {}", &key)); err_unrec(format!("Couldn't install {}", &key));
@ -196,7 +199,7 @@ pub fn upgrade(noconfirm: bool) { // upgrade all packages
.expect("Couldn't call makepkg"); .expect("Couldn't call makepkg");
match install_result.code() { match install_result.code() {
Some(0) => { Some(0) => {
uninstall_make_depend(&key); uninstall_make_depend(key);
} }
Some(_) => { Some(_) => {
err_unrec(format!("Couldn't install {}", &key)); err_unrec(format!("Couldn't install {}", &key));
@ -211,4 +214,4 @@ pub fn upgrade(noconfirm: bool) { // upgrade all packages
} }
} }
} }
} }

@ -2,26 +2,25 @@ use crate::inf;
use ansi_term::Colour; use ansi_term::Colour;
use clap::{self, crate_version}; use clap::{self, crate_version};
pub fn ver() { // print version and contributors pub fn ver() {
println!(""); // print version and contributors
inf(format!("ame - {}",crate_version!())); println!();
println!(""); inf(format!("ame - {}", crate_version!()));
inf(format!("Contributors:")); println!();
inf("Contributors:".to_string());
println!("- axtlos <axtlos@salyut.one>"); println!("- axtlos <axtlos@salyut.one>");
println!("- jnats <jnats@salyut.one>"); println!("- jnats <jnats@salyut.one>");
println!("- jasio <jasiobene@icloud.com>"); println!("- jasio <jasiobene@icloud.com>");
println!("- generic <mdc028@bucknell.edu>"); println!("- generic <mdc028@bucknell.edu>");
println!(""); println!();
inf(format!( inf("This software is licensed under the BSD 3-Clause license.".to_string());
"This software is licensed under the BSD 3-Clause license." inf("All source code is available at:".to_string());
)); println!();
inf(format!("All source code is available at:"));
println!("");
println!( println!(
"{}", "{}",
Colour::Purple Colour::Purple
.bold() .bold()
.paint("https://git.getcryst.al/crystal/ame") .paint("https://git.getcryst.al/crystal/ame")
); );
println!(""); println!();
} }

@ -1,16 +1,13 @@
pub fn noconf(args: &Vec<String>) -> bool { // noconfirm if user passed --noconfirm or added n to the end of the arg pub fn noconf(args: &[String]) -> bool {
if args.contains(&"--noconfirm".to_string()) || args[0].ends_with(&"n".to_string()) { // noconfirm if user passed --noconfirm or added n to the end of the arg
true args.contains(&"--noconfirm".to_string()) || args[0].ends_with(&"n".to_string())
} else {
false
}
} }
pub fn argssort(args: &mut Vec<String>) -> &Vec<String> { // sort the args pub fn argssort(args: &mut Vec<String>) -> &Vec<String> {
// sort the args
if args.contains(&"--noconfirm".to_string()) { if args.contains(&"--noconfirm".to_string()) {
args.retain(|x| x != &"--noconfirm".to_string()); args.retain(|x| x != &"--noconfirm".to_string());
args return args;
} else {
args
} }
args
} }

Loading…
Cancel
Save