From 8fd94a8eb5ab414e09c2ab57828fc912669de225 Mon Sep 17 00:00:00 2001 From: jnats Date: Fri, 1 Oct 2021 21:43:41 +0100 Subject: [PATCH] fixed aurdepends --- Cargo.toml | 2 +- src/main.rs | 51 +++++++-------------------------------------- src/mods.rs | 1 + src/mods/clone.rs | 24 ++++++++++----------- src/mods/inssort.rs | 45 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 66 insertions(+), 57 deletions(-) create mode 100644 src/mods/inssort.rs diff --git a/Cargo.toml b/Cargo.toml index 511a7cb..767c54d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ame" -version = "2.1.2" +version = "2.2.0" authors = [ "jnats ", "axtlos " ] edition = "2018" description = "a fast and efficient aur helper." diff --git a/src/main.rs b/src/main.rs index 978310c..506afea 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,7 @@ 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, strs::err_unrec, strs::err_rec}; -use std::{env, process::exit, process::Command, process::Stdio}; +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 std::{env, process::exit, process::Command}; fn main() { // let statements @@ -19,47 +19,12 @@ fn main() { // install 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(&pkg) - .stdout(Stdio::null()) - .status() - .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); - } - } + let pkgs = env::args().skip(2).collect(); + if oper == "-Sn" { + inssort(true, pkgs); + } else { + inssort(false, pkgs); + } // remove } else if oper == "-R" || oper == "-Rn " || oper == "-Rsn" || oper == "-Rs" || oper == "rm" { diff --git a/src/mods.rs b/src/mods.rs index b08b334..432a22d 100644 --- a/src/mods.rs +++ b/src/mods.rs @@ -8,3 +8,4 @@ pub mod upgrade; pub mod update; pub mod strs; pub mod ver; +pub mod inssort; diff --git a/src/mods/clone.rs b/src/mods/clone.rs index a9c9705..3e959f8 100644 --- a/src/mods/clone.rs +++ b/src/mods/clone.rs @@ -1,12 +1,11 @@ use git2::Repository; use std::{env, fs, path::Path, process::Command}; -use crate::mods::strs::{err_unrec, inf}; +use crate::{err_unrec, inf, inssort}; 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); - let pkgpath = Path::new(&pkgdir); let results = raur::search(&pkg).unwrap(); if results.len() == 0 { @@ -28,8 +27,8 @@ pub fn clone(noconfirm: bool, pkg: &str) { inf(format!("Cloning {} ...", pkg)); - if pkgpath.is_dir() { - let rm_result = fs::remove_dir_all(&pkgpath); + if Path::new(&pkgdir).is_dir() { + let rm_result = fs::remove_dir_all(&pkgdir); match rm_result { Ok(_) => { inf(format!("Package path for {} already found. Removing to reinstall", pkg)) @@ -57,16 +56,15 @@ pub fn clone(noconfirm: bool, pkg: &str) { err_unrec(format!("Could not enter package directory")) }} - Repository::clone(&url, &pkgpath).unwrap(); - - let cd2_result = env::set_current_dir(&pkgpath); - match cd2_result { - Ok(_) => { - inf(format!("Entering package directory for {}", pkg)) + let aurpkgname = results[0].name.to_string(); + let depends = raur::info(&[&aurpkgname]).unwrap()[0].depends.clone(); + if noconfirm == true { + inssort(true, depends); + } else { + inssort(false, depends); } - Err(_) => { - err_unrec(format!("Couldn't enter package directory for {}", pkg)) - }} + + Repository::clone(&url, Path::new(&pkgdir)).unwrap(); if noconfirm == true { inf(format!("Installing {} ...", pkg)); diff --git a/src/mods/inssort.rs b/src/mods/inssort.rs new file mode 100644 index 0000000..69d763c --- /dev/null +++ b/src/mods/inssort.rs @@ -0,0 +1,45 @@ +use crate::{clone, install, inf, err_unrec}; +use std::process::{Stdio, Command}; + +pub fn inssort(noconfirm: bool, pkgs: Vec) { + let mut repo = vec![]; + let mut aur = vec![]; + for pkg in pkgs { + let out = Command::new("pacman") + .arg("-Ss") + .arg(&pkg) + .stdout(Stdio::null()) + .status() + .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 noconfirm == true { + install(true, &repo.join(" ")); + } else { + install(false, &repo.join(" ")); + } + } + + for a in aur { + inf(format!("Installing AUR package: {}", a)); + if noconfirm == true { + clone(true, &a); + } else { + clone(false, &a); + } + } +}