added install sorting and noconfirm

i18n
jnats 3 years ago
parent afb70cbe3b
commit 12cf74ce50

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

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

@ -2,7 +2,7 @@ use git2::Repository;
use std::{env, fs, path::Path, process::Command}; use std::{env, fs, path::Path, process::Command};
use crate::mods::strs::{err_unrec, inf}; 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 cachedir = format!("{}/.cache/ame", std::env::var("HOME").unwrap());
let path = Path::new(&cachedir); let path = Path::new(&cachedir);
let pkgdir = format!("{}/{}", &cachedir, &pkg); let pkgdir = format!("{}/{}", &cachedir, &pkg);
@ -68,15 +68,30 @@ pub fn clone(pkg: &str) {
err_unrec(format!("Couldn't enter package directory for {}", pkg)) err_unrec(format!("Couldn't enter package directory for {}", pkg))
}} }}
inf(format!("Installing {} ...", pkg)); if noconfirm == true {
let install_result = Command::new("makepkg") inf(format!("Installing {} ...", pkg));
.arg("-si") let install_result = Command::new("makepkg")
.status(); .arg("-si")
match install_result { .arg("--noconfirm")
Ok(_) => { .status();
inf(format!("Succesfully installed {}", pkg)); 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 runas::Command;
use crate::mods::strs::{inf, err_unrec}; use crate::mods::strs::{inf, err_unrec};
pub fn install(pkg: &str) { pub fn install(noconfirm: bool, pkg: &str) {
let result = Command::new("pacman").arg("-Sy").arg(&pkg).status(); let pkgs: Vec<&str> = pkg.split(" ").collect();
match result { if noconfirm == true {
Ok(_) => { let result = Command::new("pacman").arg("-Sy").arg("--noconfirm").args(&pkgs).status();
inf(format!("Succesfully installed {}", pkg)) 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 runas::Command;
use crate::mods::strs::{inf, err_unrec}; 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)); inf(format!("Attempting to uninstall {}", pkg));
let result = Command::new("pacman").arg("-Rs").arg(&pkg).status(); if noconfirm == true {
match result { let result = Command::new("pacman").arg("-Rs").arg(&pkg).arg("--noconfirm").status();
Ok(_) => { match result {
println!("") 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 std::env;
use crate::mods::strs::{err_unrec, inf}; use crate::mods::strs::{err_unrec, inf};
pub fn upgrade(cachedir: &str){ pub fn upgrade(noconfirm: bool, cachedir: &str){
let result = Command::new("pacman") if noconfirm == true {
.arg("-Syu") let result = Command::new("pacman")
.status(); .arg("-Syu")
match result { .arg("--noconfirm")
Ok(_) => { .status();
inf(format!("All repo packages upgraded")) 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() { for file in std::fs::read_dir(&cachedir).unwrap() {
let dir = &file.unwrap().path(); let dir = &file.unwrap().path();

Loading…
Cancel
Save