From 957a014cc975093cab92453bc460af7acaa170d7 Mon Sep 17 00:00:00 2001 From: jnats Date: Sat, 25 Sep 2021 00:02:01 +0100 Subject: [PATCH] fixed installing and added upd --- src/main.rs | 28 +++++++++++++++++----------- src/mods.rs | 1 + src/mods/clone.rs | 7 ++++++- src/mods/update.rs | 17 +++++++++++++++++ 4 files changed, 41 insertions(+), 12 deletions(-) create mode 100644 src/mods/update.rs diff --git a/src/main.rs b/src/main.rs index c2944b6..2b4d771 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,6 @@ mod mods; -use mods::{clearcache::clearcache, clone::clone, help::help, install::install, search::{a_search, r_search}, uninstall::uninstall, upgrade::upgrade, ver::ver}; -use std::{env, process::exit, process::Command}; +use mods::{clearcache::clearcache, clone::clone, help::help, install::install, search::{a_search, r_search}, uninstall::uninstall, upgrade::upgrade, update::update, ver::ver}; +use std::{env, process::exit, process::Command, process::Stdio}; fn main() { // let statements @@ -17,12 +17,12 @@ fn main() { let oper = &args[1]; // install - if oper == "-S" || oper == "ins" || oper == "install" { + if oper == "-S" || oper == "ins" { for arg in env::args().skip(2) { let out = Command::new("pacman") .arg("-Ss") .arg(&arg) - .arg(" > /dev/null && return ${PIPESTATUS}") + .stdout(Stdio::null()) .status() .unwrap(); if out.success() { @@ -33,34 +33,40 @@ fn main() { } // remove - } else if oper == "-R" || oper == "-Rs" || oper=="rem" || oper=="remove" { + } else if oper == "-R" || oper == "-Rs" || oper=="rem" { for arg in env::args().skip(2) { uninstall(&arg); } // upgrade - } else if oper == "-Syu" || oper=="upg" || oper=="upgrade" { + } else if oper == "-Syu" || oper=="upg" { upgrade(&cache_path); - } else if oper == "-Ss" || oper=="sea" || oper=="search" { + + // update + } else if oper == "-Sy" || oper == "upd" { + update(); + + // general search + } else if oper == "-Ss" || oper=="sea" { for arg in env::args().skip(2) { r_search(&arg); a_search(&arg); } // aur search - } else if oper == "-Sa" || oper=="aursea" || oper=="aursearch" { + } else if oper == "-Sa" || oper=="aursea" { for arg in env::args().skip(2) { a_search(&arg); } // repo search - } else if oper == "-Sr" || oper=="repsea" || oper=="reposearch" { + } else if oper == "-Sr" || oper=="repsea" { for arg in env::args().skip(2) { r_search(&arg); } - // clear cache - } else if oper == "-Cc" || oper=="clr" || oper=="clear-cache" { + // clear cache !! DEBUG ONLY !! DO NOT DO THIS IF YOU DONT KNOW WHAT YOURE DOING !! + } else if oper == "-Cc" || oper=="clr" { clearcache(); // version / contrib diff --git a/src/mods.rs b/src/mods.rs index ce3e1a1..b08b334 100644 --- a/src/mods.rs +++ b/src/mods.rs @@ -5,5 +5,6 @@ pub mod install; pub mod search; pub mod uninstall; pub mod upgrade; +pub mod update; pub mod strs; pub mod ver; diff --git a/src/mods/clone.rs b/src/mods/clone.rs index dda1641..4fe1d33 100644 --- a/src/mods/clone.rs +++ b/src/mods/clone.rs @@ -7,7 +7,12 @@ pub fn clone(pkg: &str) { let path = Path::new(&cachedir); let pkgdir = format!("{}/{}", &cachedir, &pkg); let pkgpath = Path::new(&pkgdir); - let results = raur::search(&pkg).expect("a"); + let results = raur::search(&pkg).unwrap(); + + if results.len() <= 1 { + err_unrec(format!("No matching packages found")); + } + let url = format!("https://aur.archlinux.org/{}.git", results[0].name); if !path.is_dir() { diff --git a/src/mods/update.rs b/src/mods/update.rs new file mode 100644 index 0000000..df77397 --- /dev/null +++ b/src/mods/update.rs @@ -0,0 +1,17 @@ +use runas::Command; +use crate::mods::strs::{inf, err_unrec}; + +pub fn update() { + inf(format!("Syncing package repos")); + + let result = Command::new("pacman") + .arg("-Sy") + .status(); + match result { + Ok(_) => { + inf(format!("Repos succesfully synced")) + } + Err(_) => { + err_unrec(format!("Couldn't sync package repos (how?)")) + }} +}