added pkgbuild prompt and fixed noconfirm

i18n
jnats 3 years ago
parent efcfc4a546
commit 5d7c03ef3b

@ -1,6 +1,6 @@
[package]
name = "ame"
version = "2.2.4"
version = "2.3.0"
authors = [ "jnats <jnats@salyut.one>", "axtlos <axtlos@salyut.one>" ]
edition = "2018"
description = "a fast and efficient aur helper."
@ -13,3 +13,5 @@ raur = "2.0.2"
runas = "*"
ansi_term = "*"
uwuizer = "*"
text_io = "*"
moins = "*"

@ -1,14 +1,12 @@
mod mods;
use mods::{clearcache::clearcache, clone::clone, help::help, install::install, inssort::inssort, search::{a_search, r_search}, uninstall::uninstall, upgrade::upgrade, update::update, ver::ver, strs::inf, strs::err_unrec, strs::err_rec};
use mods::{clearcache::clearcache, clone::clone, help::help, install::install, inssort::inssort, search::{a_search, r_search}, uninstall::uninstall, upgrade::upgrade, update::update, ver::ver, strs::inf, strs::err_unrec, strs::err_rec, xargs::*};
use std::{env, process::exit, process::Command};
fn main() {
// let statements
let args: Vec<String> = env::args().collect();
let homepath = std::env::var("HOME").unwrap();
let cache_path = format!("/{}/.cache/ame/", homepath);
let pkgs = env::args().skip(2).collect();
let mut pkgs: Vec<String> = env::args().skip(2).collect();
// args catch
if args.len() <= 1 {
@ -17,30 +15,21 @@ fn main() {
}
let oper = &args[1];
let noconfirm: bool = noconf(&args);
argssort(&mut pkgs);
// install
if oper == "-S" || oper == "-Sn" || oper == "ins" {
if oper == "-Sn" {
inssort(true, pkgs);
} else {
inssort(false, pkgs);
}
inssort(noconfirm, pkgs);
// remove
} else if oper == "-R" || oper == "-Rn " || oper == "-Rsn" || oper == "-Rs" || oper == "rm" {
if oper == "-Rn" || oper == "-Rsn" {
uninstall(true, pkgs);
} else {
uninstall(false, pkgs);
}
uninstall(noconfirm, pkgs);
// upgrade
} else if oper == "-Syu" || oper == "-Syun" || oper == "upg" {
if oper == ("-Syun") {
upgrade(true, &cache_path);
} else {
upgrade(false, &cache_path);
}
upgrade(noconfirm);
// update
} else if oper == "-Sy" || oper == "upd" {
@ -48,22 +37,16 @@ fn main() {
// general search
} else if oper == "-Ss" || oper == "sea" {
for arg in env::args().skip(2) {
r_search(&arg);
a_search(&arg);
}
r_search(&args[2]);
a_search(&args[2]);
// aur search
} else if oper == "-Sa" || oper == "aursea" {
for arg in env::args().skip(2) {
a_search(&arg);
}
a_search(&args[2]);
// repo search
} else if oper == "-Sr" || oper == "repsea" {
for arg in env::args().skip(2) {
r_search(&arg);
}
r_search(&args[2]);
// clear cache !! DEBUG ONLY !! DO NOT DO THIS IF YOU DONT KNOW WHAT YOURE DOING !!
} else if oper == "-Cc" || oper == "clr" {

@ -9,3 +9,4 @@ pub mod update;
pub mod strs;
pub mod ver;
pub mod inssort;
pub mod xargs;

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

@ -1,6 +1,7 @@
use git2::Repository;
use moins::Moins;
use std::{env, fs, path::Path, process::Command};
use crate::{err_unrec, inf, inssort, mods::strs::succ, mods::strs::sec};
use crate::{err_unrec, inf, inssort, mods::strs::succ, mods::strs::sec, mods::strs::prompt};
pub fn clone(noconfirm: bool, pkg: &str) {
let cachedir = format!("{}/.cache/ame", std::env::var("HOME").unwrap());
@ -62,14 +63,19 @@ pub fn clone(noconfirm: bool, pkg: &str) {
// | riiiiight
let aurpkgname = results[0].name.to_string(); // v here
let depends = raur::info(&[&aurpkgname]).unwrap()[0].depends.clone();
if noconfirm == true {
inssort(true, depends);
} else {
inssort(false, depends);
}
inssort(noconfirm, depends);
Repository::clone(&url, Path::new(&pkgdir)).unwrap();
if noconfirm == false {
let pkgbuild = prompt(format!("View PKGBUILD?"));
if pkgbuild == true {
let mut pkgbld = fs::read_to_string(format!("{}/PKGBUILD", &pkgdir)).unwrap();
Moins::run(&mut pkgbld, None);
}
}
if noconfirm == true {
sec(format!("Installing {} ...", pkg));
let install_result = Command::new("makepkg")

@ -27,19 +27,11 @@ pub fn inssort(noconfirm: bool, pkgs: Vec<String>) {
if repo.len() != 0 {
sec(format!("Installing repo packages: {}", &repo.join(", ")));
if noconfirm == true {
install(true, &repo.join(" "));
} else {
install(false, &repo.join(" "));
}
install(noconfirm, &repo.join(" "));
}
for a in aur {
sec(format!("Installing AUR package: {}", a));
if noconfirm == true {
clone(true, &a);
} else {
clone(false, &a);
}
sec(format!("Installing AUR package: {}", a));
clone(noconfirm, &a);
}
}

@ -1,6 +1,7 @@
use ansi_term::Colour;
use std::{process, env};
use uwuizer::*;
use text_io::read;
pub fn inf(a: std::string::String){
if env::var("AME_UWU").unwrap_or("n/a".to_string()) == "YES" {
@ -38,6 +39,32 @@ pub fn succ(a: std::string::String) {
}
}
pub fn prompt(a: std::string::String) -> bool {
if env::var("AME_UWU").unwrap_or("n/a".to_string()) == "YES" {
println!("{} {} {}",
Colour::Purple.bold().paint("❖"),
Colour::White.bold().paint(uwuize!(&a)),
Colour::White.bold().paint("(Y/n): "));
let yn: String = read!();
if yn == "n" || yn == "N" || yn == "no" || yn == "No" {
false
} else {
true
}
} else {
println!("{} {} {}",
Colour::Purple.bold().paint("❖"),
Colour::White.bold().paint(&a),
Colour::White.bold().paint("(Y/n): "));
let yn: String = read!();
if yn == "n" || yn == "N" || yn == "no" || yn == "No" {
false
} else {
true
}
}
}
pub fn err_unrec(a: std::string::String) {
if env::var("AME_UWU").unwrap_or("n/a".to_string()) == "YES" {

@ -2,7 +2,9 @@ use runas::Command;
use std::env;
use crate::mods::strs::{err_unrec, inf, sec, succ};
pub fn upgrade(noconfirm: bool, cachedir: &str){
pub fn upgrade(noconfirm: bool){
let homepath = std::env::var("HOME").unwrap();
let cachedir = format!("/{}/.cache/ame/", homepath);
sec(format!("Performing system upgrade"));
if noconfirm == true {
let result = Command::new("pacman")

@ -3,7 +3,7 @@ use ansi_term::Colour;
pub fn ver() {
println!("");
inf(format!("ame - v2.2.4"));
inf(format!("ame - v2.3.0"));
println!("");
inf(format!("Contributors:"));
println!("- axtlos <axtlos@salyut.one>");

@ -0,0 +1,26 @@
pub fn noconf(args: &Vec<String>) -> bool {
if args.contains(&"--noconfirm".to_string()) || args[1].ends_with(&"n".to_string()) {
true
} else {
false
}
}
pub fn argssort(args: &mut Vec<String>) -> &Vec<String> {
if args.contains(&"--noconfirm".to_string()) {
args.retain(|x| x != &"--noconfirm".to_string());
println!("{:?}", args);
args
} else if args.contains(&"--pkgbuild".to_string()) {
args.retain(|x| x != &"--pkgbuild".to_string());
println!("{:?}", args);
args
} else if args.contains(&"--pkgbuild".to_string()) && args.contains(&"--noconfirm".to_string()) {
args.retain(|x| x != &"--noconfirm".to_string());
args.retain(|x| x != &"--pkgbuild".to_string());
println!("{:?}", args);
args
} else {
args
}
}
Loading…
Cancel
Save