@ -1,35 +1,42 @@
use crate ::{ clone , err_unrec , install , mods ::strs ::sec } ;
use std ::process ::{ Command , Stdio } ;
use regex ::Regex ;
use std ::process ::{ Command , Stdio } ;
pub fn inssort ( noconfirm : bool , as_dep : bool , pkgs : Vec < String > ) { // TODO: understand what the fuck is actually going on here
pub fn inssort ( noconfirm : bool , as_dep : bool , pkgs : Vec < String > ) {
// TODO: understand what the fuck is actually going on here
let mut repo = vec! [ ] ;
let mut aur = vec! [ ] ;
let re = Regex ::new ( r"(\S+)((?:>=|<=)\S+$)" ) . unwrap ( ) ;
let reg = Regex ::new ( r"((?:>=|<=)\S+$)" ) . unwrap ( ) ;
for pkg in pkgs {
match pkg . contains ( "/" ) {
true = > {
match pkg . split ( "/" ) . collect ::< Vec < & str > > ( ) [ 0 ] = = "aur" {
match pkg . contains ( '/' ) {
true = > match pkg . split ( '/' ) . collect ::< Vec < & str > > ( ) [ 0 ] = = "aur" {
true = > {
aur . push ( pkg . split ( "/" ) . collect ::< Vec < & str > > ( ) [ 1 ] . to_string ( ) ) ;
aur . push ( pkg . split ( '/' ) . collect ::< Vec < & str > > ( ) [ 1 ] . to_string ( ) ) ;
}
false = > {
let out = Command ::new ( "bash" )
. arg ( "-c" )
. arg ( format! ( "pacman -Sl {} | grep {}" , pkg . split ( "/" ) . collect ::< Vec < & str > > ( ) [ 0 ] , pkg . split ( "/" ) . collect ::< Vec < & str > > ( ) [ 1 ] ) )
. arg ( format! (
"pacman -Sl {} | grep {}" ,
pkg . split ( '/' ) . collect ::< Vec < & str > > ( ) [ 0 ] ,
pkg . split ( '/' ) . collect ::< Vec < & str > > ( ) [ 1 ]
) )
. stdout ( Stdio ::null ( ) )
. status ( )
. expect ( "Something has gone wrong." ) ;
match out . code ( ) {
Some ( 0 ) = > repo . push ( reg . replace_all ( & pkg , "" ) . to_string ( ) ) ,
Some ( 1 ) = > err_unrec ( format! ( "Package {} not found in repository {}" , pkg . split ( "/" ) . collect ::< Vec < & str > > ( ) [ 1 ] , pkg . split ( "/" ) . collect ::< Vec < & str > > ( ) [ 0 ] ) ) ,
Some ( _ ) = > err_unrec ( format! ( "Something has gone terribly wrong" ) ) ,
None = > err_unrec ( format! ( "Process terminated" ) ) ,
}
}
Some ( 1 ) = > err_unrec ( format! (
"Package {} not found in repository {}" ,
pkg . split ( '/' ) . collect ::< Vec < & str > > ( ) [ 1 ] ,
pkg . split ( '/' ) . collect ::< Vec < & str > > ( ) [ 0 ]
) ) ,
Some ( _ ) = > err_unrec ( "Something has gone terribly wrong" . to_string ( ) ) ,
None = > err_unrec ( "Process terminated" . to_string ( ) ) ,
}
}
} ,
false = > {
let caps = re . captures ( & pkg ) ;
match caps {
@ -46,8 +53,8 @@ pub fn inssort(noconfirm: bool, as_dep: bool, pkgs: Vec<String>) { // TODO: unde
match out . code ( ) {
Some ( 0 ) = > repo . push ( reg . replace_all ( & pkg , "" ) . to_string ( ) ) ,
Some ( 1 ) = > aur . push ( pkg ) ,
Some ( _ ) = > err_unrec ( format! ( "Something has gone terribly wrong" ) ) ,
None = > err_unrec ( format! ( "Process terminated" ) ) ,
Some ( _ ) = > err_unrec ( "Something has gone terribly wrong" . to_string ( ) ) ,
None = > err_unrec ( "Process terminated" . to_string ( ) ) ,
}
}
None = > {
@ -60,16 +67,16 @@ pub fn inssort(noconfirm: bool, as_dep: bool, pkgs: Vec<String>) { // TODO: unde
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" ) ) ,
Some ( _ ) = > err_unrec ( "Something has gone terribly wrong" . to_string ( ) ) ,
None = > err_unrec ( "Process terminated" . to_string ( ) ) ,
}
}
}
}
}
}
if as_dep = = false {
if repo . len ( ) ! = 0 {
if ! as_dep {
if ! repo . is_empty ( ) {
sec ( format! ( "Installing repo packages: {}" , & repo . join ( ", " ) ) ) ;
install ( noconfirm , false , & repo . join ( " " ) ) ;
}
@ -79,7 +86,7 @@ pub fn inssort(noconfirm: bool, as_dep: bool, pkgs: Vec<String>) { // TODO: unde
clone ( noconfirm , false , & a ) ;
}
} else {
if repo . len ( ) ! = 0 {
if ! repo . is_empty ( ) {
sec ( format! ( "Installing repo packages: {}" , & repo . join ( ", " ) ) ) ;
install ( noconfirm , true , & repo . join ( " " ) ) ;
}
@ -91,7 +98,8 @@ pub fn inssort(noconfirm: bool, as_dep: bool, pkgs: Vec<String>) { // TODO: unde
}
}
pub fn inssort_from_file ( noconfirm : bool , as_dep : bool , file : & str ) { // same thing as above but with a list of packages from a file
pub fn inssort_from_file ( noconfirm : bool , as_dep : bool , file : & str ) {
// same thing as above but with a list of packages from a file
let mut pkgs : Vec < String > = Vec ::new ( ) ;
let contents = std ::fs ::read_to_string ( & file ) . expect ( "Couldn't read file" ) ;
for line in contents . lines ( ) {
@ -102,28 +110,34 @@ pub fn inssort_from_file(noconfirm: bool, as_dep: bool, file: &str) { // same th
let re = Regex ::new ( r"(\S+)((?:>=|<=)\S+$)" ) . unwrap ( ) ;
let reg = Regex ::new ( r"((?:>=|<=)\S+$)" ) . unwrap ( ) ;
for pkg in pkgs {
match pkg . contains ( "/" ) {
true = > {
match pkg . split ( "/" ) . collect ::< Vec < & str > > ( ) [ 0 ] = = "aur" {
match pkg . contains ( '/' ) {
true = > match pkg . split ( '/' ) . collect ::< Vec < & str > > ( ) [ 0 ] = = "aur" {
true = > {
aur . push ( pkg . split ( "/" ) . collect ::< Vec < & str > > ( ) [ 1 ] . to_string ( ) ) ;
aur . push ( pkg . split ( '/' ) . collect ::< Vec < & str > > ( ) [ 1 ] . to_string ( ) ) ;
}
false = > {
let out = Command ::new ( "bash" )
. arg ( "-c" )
. arg ( format! ( "pacman -Sl {} | grep {}" , pkg . split ( "/" ) . collect ::< Vec < & str > > ( ) [ 0 ] , pkg . split ( "/" ) . collect ::< Vec < & str > > ( ) [ 1 ] ) )
. arg ( format! (
"pacman -Sl {} | grep {}" ,
pkg . split ( '/' ) . collect ::< Vec < & str > > ( ) [ 0 ] ,
pkg . split ( '/' ) . collect ::< Vec < & str > > ( ) [ 1 ]
) )
. stdout ( Stdio ::null ( ) )
. status ( )
. expect ( "Something has gone wrong." ) ;
match out . code ( ) {
Some ( 0 ) = > repo . push ( reg . replace_all ( & pkg , "" ) . to_string ( ) ) ,
Some ( 1 ) = > err_unrec ( format! ( "Package {} not found in repository {}" , pkg . split ( "/" ) . collect ::< Vec < & str > > ( ) [ 1 ] , pkg . split ( "/" ) . collect ::< Vec < & str > > ( ) [ 0 ] ) ) ,
Some ( _ ) = > err_unrec ( format! ( "Something has gone terribly wrong" ) ) ,
None = > err_unrec ( format! ( "Process terminated" ) ) ,
}
}
Some ( 1 ) = > err_unrec ( format! (
"Package {} not found in repository {}" ,
pkg . split ( '/' ) . collect ::< Vec < & str > > ( ) [ 1 ] ,
pkg . split ( '/' ) . collect ::< Vec < & str > > ( ) [ 0 ]
) ) ,
Some ( _ ) = > err_unrec ( "Something has gone terribly wrong" . to_string ( ) ) ,
None = > err_unrec ( "Process terminated" . to_string ( ) ) ,
}
}
} ,
false = > {
let caps = re . captures ( & pkg ) ;
match caps {
@ -140,8 +154,8 @@ pub fn inssort_from_file(noconfirm: bool, as_dep: bool, file: &str) { // same th
match out . code ( ) {
Some ( 0 ) = > repo . push ( reg . replace_all ( & pkg , "" ) . to_string ( ) ) ,
Some ( 1 ) = > aur . push ( pkg ) ,
Some ( _ ) = > err_unrec ( format! ( "Something has gone terribly wrong" ) ) ,
None = > err_unrec ( format! ( "Process terminated" ) ) ,
Some ( _ ) = > err_unrec ( "Something has gone terribly wrong" . to_string ( ) ) ,
None = > err_unrec ( "Process terminated" . to_string ( ) ) ,
}
}
None = > {
@ -154,16 +168,16 @@ pub fn inssort_from_file(noconfirm: bool, as_dep: bool, file: &str) { // same th
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" ) ) ,
Some ( _ ) = > err_unrec ( "Something has gone terribly wrong" . to_string ( ) ) ,
None = > err_unrec ( "Process terminated" . to_string ( ) ) ,
}
}
}
}
}
}
if as_dep = = false {
if repo . len ( ) ! = 0 {
if ! as_dep {
if ! repo . is_empty ( ) {
sec ( format! ( "Installing repo packages: {}" , & repo . join ( ", " ) ) ) ;
install ( noconfirm , false , & repo . join ( " " ) ) ;
}
@ -173,7 +187,7 @@ pub fn inssort_from_file(noconfirm: bool, as_dep: bool, file: &str) { // same th
clone ( noconfirm , false , & a ) ;
}
} else {
if repo . len ( ) ! = 0 {
if ! repo . is_empty ( ) {
sec ( format! ( "Installing repo packages: {}" , & repo . join ( ", " ) ) ) ;
install ( noconfirm , true , & repo . join ( " " ) ) ;
}