oh lord - full cargo clippy + fmt

i18n
michal 3 years ago
parent bbec30ead5
commit 5330758ad5

@ -2,48 +2,35 @@ mod mods;
use mods::{
clearcache::clearcache,
clone::clone,
database::{add_pkg, create_database},
help::help,
inssort::{
inssort,
inssort_from_file},
inssort::{inssort, inssort_from_file},
install::install,
purge::{
purge,
purge_from_file},
search::{
a_search,
r_search},
strs::err_rec,
strs::err_unrec,
strs::inf,
uninstall::{
uninstall,
uninstall_from_file},
update::update,
upgrade::upgrade,
ver::ver,
purge::{purge, purge_from_file},
search::{a_search, r_search},
strs::err_rec,
strs::err_unrec,
strs::inf,
uninstall::{uninstall, uninstall_from_file},
update::update,
upgrade::upgrade,
ver::ver,
xargs::*,
statpkgs::rebuild,
database::{
add_pkg,
create_database,
},
};
use std::{
env,
process::exit
};
use std::{env, process::exit};
fn main() {
if nix::unistd::Uid::effective().is_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!"));
if nix::unistd::Uid::effective().is_root() {
// check if user runs ame as root
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 mut pkgs: Vec<String> = env::args().skip(2).collect();
if args.len() <= 0 {
if args.is_empty() {
help();
exit(1);
}
@ -57,7 +44,8 @@ fn main() {
let noconfirm: bool = noconf(&args);
argssort(&mut pkgs);
match oper.as_str() { // match oper
match oper.as_str() {
// match oper
"-S" | "-Sn" | "ins" => {
inssort(noconfirm, false, pkgs); // install
}
@ -105,8 +93,9 @@ fn main() {
"-h" | "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)
.status()
.expect("Something has gone wrong.");
@ -114,12 +103,10 @@ fn main() {
match pass.code() {
Some(1) => {
err_rec(format!("No such operation \"{}\"", args.join(" ")));
inf(format!(
"Try running \"ame help\" for an overview of how to use ame"
))
inf("Try running \"ame help\" for an overview of how to use ame".to_string())
}
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 inssort;
pub mod install;
pub mod purge;
pub mod search;
pub mod statpkgs;
pub mod strs;
pub mod uninstall;
pub mod update;
pub mod upgrade;
pub mod ver;
pub mod xargs;
pub mod purge;
pub mod statpkgs;

@ -1,10 +1,11 @@
use crate::mods::strs::err_rec;
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());
err_rec(format!("Clearing cache"));
err_rec("Clearing cache".to_string());
fs::remove_dir_all(&path).unwrap();
fs::create_dir(&path).unwrap();

@ -1,11 +1,12 @@
use crate::{
err_unrec, inf, inssort, mods::database::add_pkg, mods::strs::prompt, mods::strs::sec,
mods::strs::succ, mods::purge::purge,
err_unrec, inf, inssort, mods::database::add_pkg, mods::purge::purge, mods::strs::prompt,
mods::strs::sec, mods::strs::succ,
};
use moins::Moins;
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 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())
.output()
.expect("Something has gone terribly wrong");
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();
for pkg in expl_pkgs_parse {
for i in 0 .. make_depends.len() {
match make_depends[i].contains(pkg) {
false => {
match rem_pkgs.contains(&make_depends[i]) {
false => {
rem_pkgs.push(make_depends[i].as_str().to_string());
}
_ => {}
}
#[allow(clippy::needless_range_loop)]
for i in 0..make_depends.len() {
if let false = make_depends[i].contains(pkg) {
if let false = rem_pkgs.contains(&make_depends[i]) {
rem_pkgs.push(make_depends[i].as_str().to_string());
}
_ => {}
};
}
}
if rem_pkgs.len() != 0 {
if !rem_pkgs.is_empty() {
inf(format!(
"{} installed following make dependencies: {}",
pkg,
rem_pkgs.join(", ")
));
let remove = prompt(format!("Would you like to remove them?"));
if remove == true {
let remove = prompt("Would you like to remove them?".to_string());
if remove {
purge(true, rem_pkgs);
}
}
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 path = Path::new(&cachedir);
let pkgdir = format!("{}/{}", &cachedir, &pkg);
let package = raur::info(&[pkg]).unwrap();
if package.len() == 0 {
err_unrec(format!("No matching AUR packages found"));
if package.is_empty() {
err_unrec("No matching AUR packages found".to_string());
}
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() {
let cache_result = fs::create_dir(&path);
match cache_result {
Ok(_) => inf(format!("Created cache path (first run)")),
Err(_) => err_unrec(format!("Could not create cache path")),
Ok(_) => inf("Created cache path (first run)".to_string()),
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);
match cd_result {
Ok(_) => inf(format!("Entered package directory")),
Err(_) => err_unrec(format!("Could not enter package directory")),
Ok(_) => inf("Entered package directory".to_string()),
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());
@ -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)),
_ => err_unrec(format!("Failed cloning {} into package directory", pkg)),
}
if as_dep == false {
if noconfirm == false {
let pkgbuild = prompt(format!("View PKGBUILD?"));
if !as_dep {
if !noconfirm {
let pkgbuild = prompt("View PKGBUILD?".to_string());
if pkgbuild == true {
if pkgbuild {
let mut pkgbld = fs::read_to_string(format!("{}/PKGBUILD", &pkgdir)).unwrap();
Moins::run(&mut pkgbld, None);
}
}
if noconfirm == true {
sec(format!("Installing {} ...", pkg));
sec(format!("Installing {} ...", pkg));
if noconfirm {
let install_result = Command::new("makepkg")
.arg("-si")
.arg("--noconfirm")
@ -141,7 +137,6 @@ pub fn clone(noconfirm: bool, as_dep: bool, pkg: &str) { // clone a package from
}
};
} else {
sec(format!("Installing {} ...", pkg));
let install_result = Command::new("makepkg")
.arg("-si")
.arg("--needed")
@ -162,20 +157,20 @@ pub fn clone(noconfirm: bool, as_dep: bool, pkg: &str) { // clone a package from
}
} else {
sec(format!("Installing {} ...", pkg));
let install_result = Command::new("makepkg")
.arg("-si")
.arg("--noconfirm")
.arg("--needed")
.arg("--asdeps")
.status();
match install_result {
Ok(_) => {
uninstall_make_depend(pkg);
add_pkg(false, pkg);
}
Err(_) => {
err_unrec(format!("Couldn't install {}", pkg));
}
};
let install_result = Command::new("makepkg")
.arg("-si")
.arg("--noconfirm")
.arg("--needed")
.arg("--asdeps")
.status();
match install_result {
Ok(_) => {
uninstall_make_depend(pkg);
add_pkg(false, pkg);
}
Err(_) => {
err_unrec(format!("Couldn't install {}", pkg));
}
};
}
}

@ -1,27 +1,28 @@
use crate::{err_unrec, inf};
use std::{fs, env};
use std::{env, fs};
pub fn create_database() {
let homepath = 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() {
let _cdar = fs::create_dir_all(format!("/{}/.local/ame/",homepath));
match _cdar {
Ok(_) => {
inf(format!("Created path for database (previously missing)"))
}
Err(_) => {
err_unrec(format!("Couldn't create path for database (~/.local/rhare/ame)"))
}
let _cdar = fs::create_dir_all(format!("/{}/.local/ame/", homepath));
match _cdar {
Ok(_) => {
inf("Created path for database (previously missing)".to_string());
}
Err(_) => {
err_unrec("Couldn't create path for database (~/.local/rhare/ame)".to_string())
}
}
}
let connection = sqlite::open(file).unwrap();
connection.execute(
"
connection
.execute(
"
CREATE TABLE pkgs (name TEXT, version TEXT);
",
)
.unwrap();
)
.unwrap();
}
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();
match sear_value {
"name" => {
let result = connection.iterate(format!("SELECT name FROM pkgs WHERE name = {};",&pkg), |pairs| {
for &(column, value) in pairs.iter() {
return_val = value.unwrap().to_string();
}
true
}
let result = connection.iterate(
format!("SELECT name FROM pkgs WHERE name = {};", &pkg),
|pairs| {
for &(_column, value) in pairs.iter() {
return_val = value.unwrap().to_string();
}
true
},
);
match result {
Ok(_) => {}
Err(_) => {
err_unrec(format!("Couldn't get value from database"))
}
Err(_) => err_unrec("Couldn't get value from database".to_string()),
}
},
}
"version" => {
let result = connection.iterate(format!("SELECT version FROM pkgs WHERE name = {};",&pkg), |pairs| {
for &(column, value) in pairs.iter() {
return_val = value.unwrap().to_string();
}
true
}
let result = connection.iterate(
format!("SELECT version FROM pkgs WHERE name = {};", &pkg),
|pairs| {
for &(_column, value) in pairs.iter() {
return_val = value.unwrap().to_string();
}
true
},
);
match result {
Ok(_) => {}
Err(_) => {
err_unrec(format!("Couldn't get value from database"))
}
Err(_) => err_unrec("Couldn't get value from database".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 connection = sqlite::open(file).unwrap();
for i in pkgs {
let result = connection.execute(
format!("
let result = connection.execute(format!(
"
DELETE FROM pkgs WHERE name = {};
", i),
);
match result{
Ok(_) => {
inf(format!("Removed {} from database", i))
}
Err(_) => {
err_unrec(format!("Couldn't remove {} from database", i))
}
",
i
));
match result {
Ok(_) => inf(format!("Removed {} 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_version = res[0].version.to_string();
}
let result = connection.execute(
format!("
let result = connection.execute(format!(
"
INSERT INTO pkgs (name, version) VALUES (\"{}\", \"{}\");
", package_name, package_version),
);
match result{
Ok(_) => {
inf(format!("Added {} to database", package_name))
}
Err(_) => {
err_unrec(format!("Couldn't add {} to database", package_name))
}
",
package_name, package_version
));
match result {
Ok(_) => inf(format!("Added {} 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};
pub fn help() { // print help message
println!("");
inf(format!("Usage:"));
pub fn help() {
// print help message
println!();
inf("Usage:".to_string());
println!(
"
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"
);
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.)"));
println!("");
println!();
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!();
}

@ -1,35 +1,42 @@
use crate::{clone, err_unrec, install, mods::strs::sec};
use std::process::{Command, Stdio};
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 aur = vec![];
let re = Regex::new(r"(\S+)((?:>=|<=)\S+$)").unwrap();
let reg = Regex::new(r"((?:>=|<=)\S+$)").unwrap();
for pkg in pkgs {
match pkg.contains("/") {
true => {
match pkg.split("/").collect::<Vec<&str>>()[0] == "aur" {
true => {
aur.push(pkg.split("/").collect::<Vec<&str>>()[1].to_string());
}
false => {
let out = Command::new("bash")
.arg("-c")
.arg(format!("pacman -Sl {} | grep {}", pkg.split("/").collect::<Vec<&str>>()[0],pkg.split("/").collect::<Vec<&str>>()[1]))
.stdout(Stdio::null())
.status()
.expect("Something has gone wrong.");
match out.code() {
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(format!("Something has gone terribly wrong")),
None => err_unrec(format!("Process terminated")),
}
match pkg.contains('/') {
true => match pkg.split('/').collect::<Vec<&str>>()[0] == "aur" {
true => {
aur.push(pkg.split('/').collect::<Vec<&str>>()[1].to_string());
}
false => {
let out = Command::new("bash")
.arg("-c")
.arg(format!(
"pacman -Sl {} | grep {}",
pkg.split('/').collect::<Vec<&str>>()[0],
pkg.split('/').collect::<Vec<&str>>()[1]
))
.stdout(Stdio::null())
.status()
.expect("Something has gone wrong.");
match out.code() {
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 => {
let caps = re.captures(&pkg);
match caps {
@ -46,8 +53,8 @@ pub fn inssort(noconfirm: bool, as_dep: bool, pkgs: Vec<String>) { // TODO: unde
match out.code() {
Some(0) => repo.push(reg.replace_all(&pkg, "").to_string()),
Some(1) => aur.push(pkg),
Some(_) => err_unrec(format!("Something has gone terribly wrong")),
None => err_unrec(format!("Process terminated")),
Some(_) => err_unrec("Something has gone terribly wrong".to_string()),
None => err_unrec("Process terminated".to_string()),
}
}
None => {
@ -60,16 +67,16 @@ pub fn inssort(noconfirm: bool, as_dep: bool, pkgs: Vec<String>) { // TODO: unde
match out.code() {
Some(0) => repo.push(pkg),
Some(1) => aur.push(pkg),
Some(_) => err_unrec(format!("Something has gone terribly wrong")),
None => err_unrec(format!("Process terminated")),
Some(_) => err_unrec("Something has gone terribly wrong".to_string()),
None => err_unrec("Process terminated".to_string()),
}
}
}
}
}
}
if as_dep == false {
if repo.len() != 0 {
if !as_dep {
if !repo.is_empty() {
sec(format!("Installing repo packages: {}", &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);
}
} else {
if repo.len() != 0 {
if !repo.is_empty() {
sec(format!("Installing repo packages: {}", &repo.join(", ")));
install(noconfirm, true,&repo.join(" "));
install(noconfirm, true, &repo.join(" "));
}
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 contents = std::fs::read_to_string(&file).expect("Couldn't read file");
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 reg = Regex::new(r"((?:>=|<=)\S+$)").unwrap();
for pkg in pkgs {
match pkg.contains("/") {
true => {
match pkg.split("/").collect::<Vec<&str>>()[0] == "aur" {
true => {
aur.push(pkg.split("/").collect::<Vec<&str>>()[1].to_string());
}
false => {
let out = Command::new("bash")
.arg("-c")
.arg(format!("pacman -Sl {} | grep {}", pkg.split("/").collect::<Vec<&str>>()[0],pkg.split("/").collect::<Vec<&str>>()[1]))
.stdout(Stdio::null())
.status()
.expect("Something has gone wrong.");
match out.code() {
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(format!("Something has gone terribly wrong")),
None => err_unrec(format!("Process terminated")),
}
match pkg.contains('/') {
true => match pkg.split('/').collect::<Vec<&str>>()[0] == "aur" {
true => {
aur.push(pkg.split('/').collect::<Vec<&str>>()[1].to_string());
}
false => {
let out = Command::new("bash")
.arg("-c")
.arg(format!(
"pacman -Sl {} | grep {}",
pkg.split('/').collect::<Vec<&str>>()[0],
pkg.split('/').collect::<Vec<&str>>()[1]
))
.stdout(Stdio::null())
.status()
.expect("Something has gone wrong.");
match out.code() {
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 => {
let caps = re.captures(&pkg);
match caps {
@ -140,8 +154,8 @@ pub fn inssort_from_file(noconfirm: bool, as_dep: bool, file: &str) { // same th
match out.code() {
Some(0) => repo.push(reg.replace_all(&pkg, "").to_string()),
Some(1) => aur.push(pkg),
Some(_) => err_unrec(format!("Something has gone terribly wrong")),
None => err_unrec(format!("Process terminated")),
Some(_) => err_unrec("Something has gone terribly wrong".to_string()),
None => err_unrec("Process terminated".to_string()),
}
}
None => {
@ -154,16 +168,16 @@ pub fn inssort_from_file(noconfirm: bool, as_dep: bool, file: &str) { // same th
match out.code() {
Some(0) => repo.push(pkg),
Some(1) => aur.push(pkg),
Some(_) => err_unrec(format!("Something has gone terribly wrong")),
None => err_unrec(format!("Process terminated")),
Some(_) => err_unrec("Something has gone terribly wrong".to_string()),
None => err_unrec("Process terminated".to_string()),
}
}
}
}
}
}
if as_dep == false {
if repo.len() != 0 {
if !as_dep {
if !repo.is_empty() {
sec(format!("Installing repo packages: {}", &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);
}
} else {
if repo.len() != 0 {
if !repo.is_empty() {
sec(format!("Installing repo packages: {}", &repo.join(", ")));
install(noconfirm, true,&repo.join(" "));
install(noconfirm, true, &repo.join(" "));
}
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);
}
}
}
}

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

@ -1,120 +1,121 @@
use crate::mods::{
database::rem_pkg,
strs::{err_rec, err_unrec, sec, succ},
};
use runas::Command;
use std::{fs, path::Path};
pub fn purge(noconfirm: bool, pkgs: Vec<String>) { // purge packages
sec(format!(
"Attempting to uninstall packages: {}",
&pkgs.join(" ")
));
if noconfirm == true {
let result = Command::new("pacman")
.arg("-Rsu")
.args(&pkgs)
.arg("--noconfirm")
.status()
.expect("Couldn't call pacman");
match result.code() {
Some(0) => {
succ(format!(
"Succesfully uninstalled packages: {}",
&pkgs.join(" ")
));
rem_pkg(&pkgs);
}
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")
.arg("-Rsu")
.args(&pkgs)
.status()
.expect("Couldn't call pacman");
match result.code() {
Some(0) => {
succ(format!(
"Succesfully uninstalled packages: {}",
&pkgs.join(" ")
));
rem_pkg(&pkgs);
}
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);
let path = Path::new(&pkgdir);
if path.is_dir() {
let rm_result = fs::remove_dir_all(&path);
match rm_result {
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
let mut pkgs: Vec<String> = Vec::new();
let contents = std::fs::read_to_string(&file).expect("Couldn't read file");
for line in contents.lines() {
pkgs.push(line.to_string());
}
sec(format!(
"Attempting to uninstall packages: {}",
&pkgs.join(" ")
));
if noconfirm == true {
let result = Command::new("pacman")
.arg("-Rsu")
.args(&pkgs)
.arg("--noconfirm")
.status()
.expect("Couldn't call pacman");
match result.code() {
Some(0) => {
succ(format!(
"Succesfully uninstalled packages: {}",
&pkgs.join(" ")
));
rem_pkg(&pkgs);
}
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")
.arg("-Rsu")
.args(&pkgs)
.status()
.expect("Couldn't call pacman");
match result.code() {
Some(0) => {
succ(format!(
"Succesfully uninstalled packages: {}",
&pkgs.join(" ")
));
rem_pkg(&pkgs);
}
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);
let path = Path::new(&pkgdir);
if path.is_dir() {
let rm_result = fs::remove_dir_all(&path);
match rm_result {
Ok(_) => succ(format!("Removed AUR cache directory for {}", pkg)),
Err(_) => err_unrec(format!("Failed to remove AUR cache directory for {}", pkg)),
};
}
}
}
use crate::mods::{
database::rem_pkg,
strs::{err_rec, err_unrec, sec, succ},
};
use runas::Command;
use std::{fs, path::Path};
pub fn purge(noconfirm: bool, pkgs: Vec<String>) {
// purge packages
sec(format!(
"Attempting to uninstall packages: {}",
&pkgs.join(" ")
));
if noconfirm {
let result = Command::new("pacman")
.arg("-Rsu")
.args(&pkgs)
.arg("--noconfirm")
.status()
.expect("Couldn't call pacman");
match result.code() {
Some(0) => {
succ(format!(
"Succesfully uninstalled packages: {}",
&pkgs.join(" ")
));
rem_pkg(&pkgs);
}
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")
.arg("-Rsu")
.args(&pkgs)
.status()
.expect("Couldn't call pacman");
match result.code() {
Some(0) => {
succ(format!(
"Succesfully uninstalled packages: {}",
&pkgs.join(" ")
));
rem_pkg(&pkgs);
}
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);
let path = Path::new(&pkgdir);
if path.is_dir() {
let rm_result = fs::remove_dir_all(&path);
match rm_result {
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
let mut pkgs: Vec<String> = Vec::new();
let contents = std::fs::read_to_string(&file).expect("Couldn't read file");
for line in contents.lines() {
pkgs.push(line.to_string());
}
sec(format!(
"Attempting to uninstall packages: {}",
&pkgs.join(" ")
));
if noconfirm {
let result = Command::new("pacman")
.arg("-Rsu")
.args(&pkgs)
.arg("--noconfirm")
.status()
.expect("Couldn't call pacman");
match result.code() {
Some(0) => {
succ(format!(
"Succesfully uninstalled packages: {}",
&pkgs.join(" ")
));
rem_pkg(&pkgs);
}
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")
.arg("-Rsu")
.args(&pkgs)
.status()
.expect("Couldn't call pacman");
match result.code() {
Some(0) => {
succ(format!(
"Succesfully uninstalled packages: {}",
&pkgs.join(" ")
));
rem_pkg(&pkgs);
}
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);
let path = Path::new(&pkgdir);
if path.is_dir() {
let rm_result = fs::remove_dir_all(&path);
match rm_result {
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 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);
for r in &results {
if r.len() == 0 {
err_rec(format!("No matching AUR packages found"));
if r.is_empty() {
err_rec("No matching AUR packages found".to_string());
}
for res in r {
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")
.arg("-Ss")
.arg(&pkg)
.status()
.unwrap();
match result.code() {
Some(0) => succ(format!("Repo search successful")),
Some(1) => 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")),
Some(0) => succ("Repo search successful".to_string()),
Some(1) => err_rec("No matching repo packages found".to_string()),
Some(_) => err_unrec("Someting went terribly wrong".to_string()),
None => err_unrec("Couldn't search pacman repos".to_string()),
};
}

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

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

@ -5,12 +5,13 @@ use crate::mods::{
use runas::Command;
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!(
"Attempting to uninstall packages: {}",
&pkgs.join(" ")
));
if noconfirm == true {
if noconfirm {
let result = Command::new("pacman")
.arg("-Ru")
.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 contents = std::fs::read_to_string(&file).expect("Couldn't read file");
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: {}",
&pkgs.join(" ")
));
if noconfirm == true {
if noconfirm {
let result = Command::new("pacman")
.arg("-Ru")
.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 runas::Command;
pub fn update() { // update the repositories
sec(format!("Syncing package repos"));
pub fn update() {
// update the repositories
sec("Syncing package repos".to_string());
let result = Command::new("pacman")
.arg("-Sy")
.status()
.expect("Couldn't call pacman");
match result.code() {
Some(0) => succ(format!("Repos succesfully synced")),
Some(_) => err_unrec(format!("Couldn't sync package repos")),
None => err_unrec(format!("Couldn't sync package repos")),
Some(0) => succ("Repos succesfully synced".to_string()),
Some(_) => err_unrec("Couldn't sync package repos".to_string()),
None => err_unrec("Couldn't sync package repos".to_string()),
}
}

@ -1,28 +1,31 @@
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 std::{env, fs, path::Path};
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();
if make_depends.len() != 0 {
if !make_depends.is_empty() {
inf(format!(
"{} installed following make dependencies: {}",
pkg,
make_depends.join(", ")
));
let remove = prompt(format!("Would you like to remove them?"));
if remove == true {
let remove = prompt("Would you like to remove them?".to_string());
if remove {
uninstall(true, make_depends);
}
}
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 cachedir = format!("/{}/.cache/ame/", homepath);
let cache_exists = Path::new(&format!("/{}/.cache/ame/", homepath)).is_dir();
@ -33,12 +36,8 @@ pub fn upgrade(noconfirm: bool) { // upgrade all packages
} else {
let _cdar = fs::create_dir_all(format!("/{}/.local/ame/", homepath));
match _cdar {
Ok(_) => {
inf(format!("Created cache directory (previously missing)"))
}
Err(_) => {
err_unrec(format!("Couldn't create cache directory"))
}
Ok(_) => inf("Created cache directory (previously missing)".to_string()),
Err(_) => err_unrec("Couldn't create cache directory".to_string()),
}
err_rec(String::from("Database wasn't found, creating new one"));
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");
if cache_exists == false {
if !cache_exists {
let cachecreate = fs::create_dir_all(&cachedir);
match cachecreate {
Ok(_) => inf(format!("Creating cachedir. (didn't exist previously)")),
Err(_) => err_unrec(format!("Couldn't create cachedir")),
Ok(_) => inf("Creating cachedir. (didn't exist previously)".to_string()),
Err(_) => err_unrec("Couldn't create cachedir".to_string()),
}
}
sec(format!("Performing system upgrade"));
if noconfirm == true {
sec("Performing system upgrade".to_string());
if noconfirm {
let result = Command::new("pacman")
.arg("-Syu")
.arg("--noconfirm")
.status()
.expect("Couldn't call pacman");
match result.code() {
Some(0) => succ(format!("All repo packages upgraded")),
Some(_) => err_unrec(format!("Couldn't upgrade packages")),
None => err_unrec(format!("Couldn't upgrade packages")),
Some(0) => succ("All repo packages upgraded".to_string()),
Some(_) => err_unrec("Couldn't upgrade packages".to_string()),
None => err_unrec("Couldn't upgrade packages".to_string()),
};
} else {
let result = Command::new("pacman")
@ -71,28 +70,28 @@ pub fn upgrade(noconfirm: bool) { // upgrade all packages
.status()
.expect("Couldn't call pacman");
match result.code() {
Some(0) => succ(format!("All repo packages upgraded")),
Some(_) => err_unrec(format!("Couldn't upgrade packages")),
None => err_unrec(format!("Couldn't upgrade packages")),
Some(0) => succ("All repo packages upgraded".to_string()),
Some(_) => err_unrec("Couldn't upgrade packages".to_string()),
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 {
let results = raur::search(format!("{}", key));
for res in results {
let results = raur::search(key.to_string());
if let Ok(res) = results {
let url = format!("https://aur.archlinux.org/{}.git", key);
let package = raur::info(&[key]).unwrap();
let version = get_value(&key, "version");
let version = get_value(key, "version");
if res[0].version.contains(&version) {
let keydir = format!("{}{}", &cachedir, &key);
if Path::new(&keydir).is_dir() {
let cd_result = env::set_current_dir(&keydir);
match cd_result {
Ok(_) => inf(format!("Entered package directory")),
Err(_) => err_unrec(format!("Could not enter package directory")),
Ok(_) => inf("Entered package directory".to_string()),
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));
let install_result = std::process::Command::new("makepkg")
@ -102,7 +101,7 @@ pub fn upgrade(noconfirm: bool) { // upgrade all packages
.status();
match install_result {
Ok(_) => {
uninstall_make_depend(&key);
uninstall_make_depend(key);
}
Err(_) => {
err_unrec(format!("Couldn't install {}", &key));
@ -117,7 +116,7 @@ pub fn upgrade(noconfirm: bool) { // upgrade all packages
.expect("Couldn't call makepkg");
match install_result.code() {
Some(0) => {
uninstall_make_depend(&key);
uninstall_make_depend(key);
}
Some(_) => {
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);
match cd_result {
Ok(_) => inf(format!("Entered package directory")),
Err(_) => err_unrec(format!("Could not enter package directory")),
Ok(_) => inf("Entered package directory".to_string()),
Err(_) => err_unrec("Could not enter package directory".to_string()),
}
inssort(true, true, package[0].depends.clone());
@ -169,8 +168,12 @@ pub fn upgrade(noconfirm: bool) { // upgrade all packages
Some(0) => {
inf(format!("Cloning {} into package directory", &key));
}
Some(_) => err_unrec(format!("Failed cloning {} into package directory", &key)),
_ => 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))
}
}
}
@ -182,7 +185,7 @@ pub fn upgrade(noconfirm: bool) { // upgrade all packages
.status();
match install_result {
Ok(_) => {
uninstall_make_depend(&key);
uninstall_make_depend(key);
}
Err(_) => {
err_unrec(format!("Couldn't install {}", &key));
@ -196,7 +199,7 @@ pub fn upgrade(noconfirm: bool) { // upgrade all packages
.expect("Couldn't call makepkg");
match install_result.code() {
Some(0) => {
uninstall_make_depend(&key);
uninstall_make_depend(key);
}
Some(_) => {
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 clap::{self, crate_version};
pub fn ver() { // print version and contributors
println!("");
inf(format!("ame - {}",crate_version!()));
println!("");
inf(format!("Contributors:"));
pub fn ver() {
// print version and contributors
println!();
inf(format!("ame - {}", crate_version!()));
println!();
inf("Contributors:".to_string());
println!("- axtlos <axtlos@salyut.one>");
println!("- jnats <jnats@salyut.one>");
println!("- jasio <jasiobene@icloud.com>");
println!("- generic <mdc028@bucknell.edu>");
println!("");
inf(format!(
"This software is licensed under the BSD 3-Clause license."
));
inf(format!("All source code is available at:"));
println!("");
println!();
inf("This software is licensed under the BSD 3-Clause license.".to_string());
inf("All source code is available at:".to_string());
println!();
println!(
"{}",
Colour::Purple
.bold()
.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
if args.contains(&"--noconfirm".to_string()) || args[0].ends_with(&"n".to_string()) {
true
} else {
false
}
pub fn noconf(args: &[String]) -> bool {
// noconfirm if user passed --noconfirm or added n to the end of the arg
args.contains(&"--noconfirm".to_string()) || args[0].ends_with(&"n".to_string())
}
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()) {
args.retain(|x| x != &"--noconfirm".to_string());
args
} else {
args
return args;
}
args
}

Loading…
Cancel
Save