added install sorting and noconfirm

i18n
jnats 3 years ago
parent afb70cbe3b
commit 12cf74ce50

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

@ -1,5 +1,6 @@
mod mods;
use mods::{clearcache::clearcache, clone::clone, help::help, install::install, search::{a_search, r_search}, uninstall::uninstall, upgrade::upgrade, update::update, ver::ver, strs::inf};
use mods::{clearcache::clearcache, clone::clone, help::help, install::install, search::{a_search, r_search}, uninstall::uninstall, upgrade::upgrade, update::update, ver::ver, strs::inf, strs::err_unrec};
use std::{env, process::exit, process::Command, process::Stdio};
fn main() {
@ -17,32 +18,69 @@ fn main() {
let oper = &args[1];
// install
if oper == "-S" || oper == "ins" {
for arg in env::args().skip(2) {
if oper == "-S" || oper == "-Sn" || oper == "ins" {
let pkgs = env::args().skip(2);
let mut repo = vec![];
let mut aur = vec![];
for pkg in pkgs {
let out = Command::new("pacman")
.arg("-Ss")
.arg(&arg)
.arg(&pkg)
.stdout(Stdio::null())
.status()
.expect("");
if out.code() == Some(0) {
inf(format!("Installing {}", arg));
install(&arg);
} else {
inf(format!("Cloning {} from the AUR", arg));
clone(&arg);
.expect("Something has gone wrong.");
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"))
}}}
if repo.len() != 0 {
inf(format!("Installing repo packages: {}", &repo.join(", ")));
if oper == "-Sn" {
install(true, &repo.join(" "));
} else {
install(false, &repo.join(" "));
}
}
for a in aur {
inf(format!("Installing AUR package: {}", a));
if oper == "-Sn" {
clone(true, &a);
} else {
clone(false, &a);
}
}
}
// remove
} else if oper == "-R" || oper == "-Rs" || oper == "rm" {
for arg in env::args().skip(2) {
uninstall(&arg);
} else if oper == "-R" || oper == "-Rn " || oper == "-Rsn" || oper == "-Rs" || oper == "rm" {
if oper == "-Rn" || oper == "-Rsn" {
for arg in env::args().skip(2) {
uninstall(true, &arg);
}
} else {
for arg in env::args().skip(2) {
uninstall(false, &arg);
}
}
// upgrade
} else if oper == "-Syu" || oper == "upg" {
upgrade(&cache_path);
} else if oper == "-Syu" || oper == "-Syun" || oper == "upg" {
inf(format!("Performing system upgrade"));
if oper == ("-Syun") {
upgrade(true, &cache_path);
} else {
upgrade(false, &cache_path);
}
// update
} else if oper == "-Sy" || oper == "upd" {

@ -2,7 +2,7 @@ use git2::Repository;
use std::{env, fs, path::Path, process::Command};
use crate::mods::strs::{err_unrec, inf};
pub fn clone(pkg: &str) {
pub fn clone(noconfirm: bool, pkg: &str) {
let cachedir = format!("{}/.cache/ame", std::env::var("HOME").unwrap());
let path = Path::new(&cachedir);
let pkgdir = format!("{}/{}", &cachedir, &pkg);
@ -68,15 +68,30 @@ pub fn clone(pkg: &str) {
err_unrec(format!("Couldn't enter package directory for {}", pkg))
}}
inf(format!("Installing {} ...", pkg));
let install_result = Command::new("makepkg")
.arg("-si")
.status();
match install_result {
Ok(_) => {
inf(format!("Succesfully installed {}", pkg));
if noconfirm == true {
inf(format!("Installing {} ...", pkg));
let install_result = Command::new("makepkg")
.arg("-si")
.arg("--noconfirm")
.status();
match install_result {
Ok(_) => {
inf(format!("Succesfully installed {}", pkg));
}
Err(_) => {
err_unrec(format!("Couldn't install {}", pkg));
}};
} else {
inf(format!("Installing {} ...", pkg));
let install_result = Command::new("makepkg")
.arg("-si")
.status();
match install_result {
Ok(_) => {
inf(format!("Succesfully installed {}", pkg));
}
Err(_) => {
err_unrec(format!("Couldn't install {}", pkg));
}};
}
Err(_) => {
err_unrec(format!("Couldn't install {}", pkg));
}};
}

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

@ -1,14 +1,25 @@
use runas::Command;
use crate::mods::strs::{inf, err_unrec};
pub fn uninstall(pkg: &str) {
pub fn uninstall(noconfirm: bool, pkg: &str) {
inf(format!("Attempting to uninstall {}", pkg));
let result = Command::new("pacman").arg("-Rs").arg(&pkg).status();
match result {
Ok(_) => {
println!("")
if noconfirm == true {
let result = Command::new("pacman").arg("-Rs").arg(&pkg).arg("--noconfirm").status();
match result {
Ok(_) => {
println!("")
}
Err(_) => {
err_unrec(format!("Couldn't uninstall {}", pkg))
}};
} else {
let result = Command::new("pacman").arg("-Rs").arg(&pkg).status();
match result {
Ok(_) => {
println!("")
}
Err(_) => {
err_unrec(format!("Couldn't uninstall {}", pkg))
}};
}
Err(_) => {
err_unrec(format!("Couldn't uninstall {}", pkg))
}};
}

@ -2,17 +2,31 @@ use runas::Command;
use std::env;
use crate::mods::strs::{err_unrec, inf};
pub fn upgrade(cachedir: &str){
let result = Command::new("pacman")
.arg("-Syu")
.status();
match result {
Ok(_) => {
inf(format!("All repo packages upgraded"))
pub fn upgrade(noconfirm: bool, cachedir: &str){
if noconfirm == true {
let result = Command::new("pacman")
.arg("-Syu")
.arg("--noconfirm")
.status();
match result {
Ok(_) => {
inf(format!("All repo packages upgraded"))
}
Err(_) => {
err_unrec(format!("Couldn't upgrade packages"))
}};
} else {
let result = Command::new("pacman")
.arg("-Syu")
.status();
match result {
Ok(_) => {
inf(format!("All repo packages upgraded"))
}
Err(_) => {
err_unrec(format!("Couldn't upgrade packages"))
}};
}
Err(_) => {
err_unrec(format!("Couldn't upgrade packages"))
}};
for file in std::fs::read_dir(&cachedir).unwrap() {
let dir = &file.unwrap().path();

Loading…
Cancel
Save