@ -2,7 +2,7 @@
#![ allow(clippy::too_many_lines) ]
use args ::Args ;
use clap ::{ Parser, CommandFactory} ;
use clap ::{ CommandFactory, Parser } ;
use clap_complete ::{ Generator , Shell } ;
use internal ::commands ::ShellCommand ;
use internal ::error ::SilentUnwrap ;
@ -31,7 +31,6 @@ fn main() {
crash ! ( AppExitCode ::RunAsRoot , "Running amethyst as root is disallowed as it can lead to system breakage. Instead, amethyst will prompt you when it needs superuser permissions" ) ;
}
// Parse arguments
let args : Args = Args ::parse ( ) ;
@ -76,22 +75,28 @@ fn main() {
} ;
// List of possible options
let opers = vec! [ "install" , "remove" , "upgrade" , "search" , "query" , "info" , "clean" , "diff" , "gencomp" ] ;
let opers = vec! [
"install" , "remove" , "upgrade" , "search" , "query" , "info" , "clean" , "diff" , "gencomp" ,
] ;
// If arg is completely unrecognized, attempt to pass it to pacman
match args ::Args ::command ( ) . get_matches ( ) . subcommand ( ) {
Some ( ( ext , ext_m ) ) = > {
if ! opers . contains ( & ext ) {
let mut m = ext_m . values_of ( "" ) . unwrap_or_default ( ) . collect ::< Vec < & str > > ( ) ;
m . insert ( 0 , ext ) ;
info ! ( "Passing unrecognized flags \"{}\" to pacman" , m . join ( " " ) ) ;
let child = ShellCommand ::pacman ( ) . args ( m ) . elevated ( ) . wait ( ) . silent_unwrap ( AppExitCode ::PacmanError ) ;
std ::process ::exit ( child . code ( ) . unwrap_or ( 1 ) ) ;
}
if let Some ( ( ext , ext_m ) ) = args ::Args ::command ( ) . get_matches ( ) . subcommand ( ) {
if ! opers . contains ( & ext ) {
let mut m = ext_m
. values_of ( "" )
. unwrap_or_default ( )
. collect ::< Vec < & str > > ( ) ;
m . insert ( 0 , ext ) ;
info ! ( "Passing unrecognized flags \"{}\" to pacman" , m . join ( " " ) ) ;
let child = ShellCommand ::pacman ( )
. args ( m )
. elevated ( )
. wait ( )
. silent_unwrap ( AppExitCode ::PacmanError ) ;
std ::process ::exit ( child . code ( ) . unwrap_or ( 1 ) ) ;
}
_ = > { }
}
// Match args
@ -115,8 +120,6 @@ fn main() {
cmd_gencomp ( & gencomp_args ) ;
}
}
}
fn cmd_install ( args : InstallArgs , options : Options , cachedir : & str ) {
@ -239,8 +242,12 @@ fn cmd_search(args: &SearchArgs, options: Options) {
}
fn cmd_query ( args : & QueryArgs ) {
let aur = args . aur | | env ::args ( ) . collect ::< Vec < String > > ( ) [ 1 ] = = "-Qa" | | env ::args ( ) . collect ::< Vec < String > > ( ) [ 1 ] = = "-Qm" ;
let repo = args . repo | | env ::args ( ) . collect ::< Vec < String > > ( ) [ 1 ] = = "-Qr" | | env ::args ( ) . collect ::< Vec < String > > ( ) [ 1 ] = = "-Qn" ;
let aur = args . aur
| | env ::args ( ) . collect ::< Vec < String > > ( ) [ 1 ] = = "-Qa"
| | env ::args ( ) . collect ::< Vec < String > > ( ) [ 1 ] = = "-Qm" ;
let repo = args . repo
| | env ::args ( ) . collect ::< Vec < String > > ( ) [ 1 ] = = "-Qr"
| | env ::args ( ) . collect ::< Vec < String > > ( ) [ 1 ] = = "-Qn" ;
let both = ! aur & & ! repo ;
if aur {