mirror of
https://github.com/Jguer/yay
synced 2024-10-06 08:09:11 +00:00
Excluding from installation
#ItWoksOnMyMachine
This commit is contained in:
parent
0301eb0440
commit
d737c99c81
77
cmd.go
77
cmd.go
|
@ -347,16 +347,39 @@ func BuildRange(input string) ([]int, error) {
|
||||||
return BuildIntRange(rangeStart, rangeEnd), err
|
return BuildIntRange(rangeStart, rangeEnd), err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Contains returns wheter e is present in s
|
||||||
|
func contains(s []string, e string) bool {
|
||||||
|
for _, a := range s {
|
||||||
|
if a == e {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemoveIntListFromList removes all src's elements that are present in target
|
||||||
|
func removeListFromList(src, target []string) []string {
|
||||||
|
max := len(target)
|
||||||
|
for i := 0; i < max; i++ {
|
||||||
|
if contains(src, target[i]) {
|
||||||
|
target = append(target[:i], target[i+1:]...)
|
||||||
|
max--
|
||||||
|
i--
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return target
|
||||||
|
}
|
||||||
|
|
||||||
// NumberMenu presents a CLI for selecting packages to install.
|
// NumberMenu presents a CLI for selecting packages to install.
|
||||||
func numberMenu(pkgS []string, flags []string) (err error) {
|
func numberMenu(pkgS []string, flags []string) (err error) {
|
||||||
var num int
|
var num int
|
||||||
|
|
||||||
aq, err := narrowSearch(pkgS, true)
|
aurQ, err := narrowSearch(pkgS, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Error during AUR search:", err)
|
fmt.Println("Error during AUR search:", err)
|
||||||
}
|
}
|
||||||
numaq := len(aq)
|
numaq := len(aurQ)
|
||||||
pq, numpq, err := queryRepo(pkgS)
|
repoQ, numpq, err := queryRepo(pkgS)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -366,11 +389,11 @@ func numberMenu(pkgS []string, flags []string) (err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.SortMode == BottomUp {
|
if config.SortMode == BottomUp {
|
||||||
aq.printSearch(numpq + 1)
|
aurQ.printSearch(numpq + 1)
|
||||||
pq.printSearch()
|
repoQ.printSearch()
|
||||||
} else {
|
} else {
|
||||||
pq.printSearch()
|
repoQ.printSearch()
|
||||||
aq.printSearch(numpq + 1)
|
aurQ.printSearch(numpq + 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("\x1b[32m%s %s\x1b[0m\nNumbers: ",
|
fmt.Printf("\x1b[32m%s %s\x1b[0m\nNumbers: ",
|
||||||
|
@ -384,10 +407,13 @@ func numberMenu(pkgS []string, flags []string) (err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
numberString := string(numberBuf)
|
numberString := string(numberBuf)
|
||||||
var aurI []string
|
var aurI, aurNI, repoNI, repoI []string
|
||||||
var repoI []string
|
|
||||||
result := strings.Fields(numberString)
|
result := strings.Fields(numberString)
|
||||||
for _, numS := range result {
|
for _, numS := range result {
|
||||||
|
negate := numS[0] == '^'
|
||||||
|
if negate {
|
||||||
|
numS = numS[1:]
|
||||||
|
}
|
||||||
var numbers []int
|
var numbers []int
|
||||||
num, err = strconv.Atoi(numS)
|
num, err = strconv.Atoi(numS)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -401,24 +427,49 @@ func numberMenu(pkgS []string, flags []string) (err error) {
|
||||||
|
|
||||||
// Install package
|
// Install package
|
||||||
for _, x := range numbers {
|
for _, x := range numbers {
|
||||||
|
var target string
|
||||||
if x > numaq+numpq || x <= 0 {
|
if x > numaq+numpq || x <= 0 {
|
||||||
continue
|
continue
|
||||||
} else if x > numpq {
|
} else if x > numpq {
|
||||||
if config.SortMode == BottomUp {
|
if config.SortMode == BottomUp {
|
||||||
aurI = append(aurI, aq[numaq+numpq-x].Name)
|
target = aurQ[numaq+numpq-x].Name
|
||||||
} else {
|
} else {
|
||||||
aurI = append(aurI, aq[x-numpq-1].Name)
|
target = aurQ[x-numpq-1].Name
|
||||||
|
}
|
||||||
|
if negate {
|
||||||
|
aurNI = append(aurNI, target)
|
||||||
|
} else {
|
||||||
|
aurI = append(aurI, target)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if config.SortMode == BottomUp {
|
if config.SortMode == BottomUp {
|
||||||
repoI = append(repoI, pq[numpq-x].Name())
|
target = repoQ[numpq-x].Name()
|
||||||
} else {
|
} else {
|
||||||
repoI = append(repoI, pq[x-1].Name())
|
target = repoQ[x-1].Name()
|
||||||
|
}
|
||||||
|
if negate {
|
||||||
|
repoNI = append(repoNI, target)
|
||||||
|
} else {
|
||||||
|
repoI = append(repoI, target)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(repoI) == 0 && len(aurI) == 0 &&
|
||||||
|
(len(aurNI) > 0 || len(repoNI) > 0) {
|
||||||
|
// If no package was specified, only exclusions, exclude from all the
|
||||||
|
// packages
|
||||||
|
for _, pack := range aurQ {
|
||||||
|
aurI = append(aurI, pack.Name)
|
||||||
|
}
|
||||||
|
for _, pack := range repoQ {
|
||||||
|
repoI = append(repoI, pack.Name())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
aurI = removeListFromList(aurNI, aurI)
|
||||||
|
repoI = removeListFromList(repoNI, repoI)
|
||||||
|
|
||||||
if len(repoI) != 0 {
|
if len(repoI) != 0 {
|
||||||
err = passToPacman("-S", repoI, flags)
|
err = passToPacman("-S", repoI, flags)
|
||||||
}
|
}
|
||||||
|
|
16
upgrade.go
16
upgrade.go
|
@ -273,7 +273,8 @@ func upRepo(local []alpm.Package) (upSlice, error) {
|
||||||
return slice, nil
|
return slice, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func contains(s []int, e int) bool {
|
//Contains returns wheter e is present in s
|
||||||
|
func containsInt(s []int, e int) bool {
|
||||||
for _, a := range s {
|
for _, a := range s {
|
||||||
if a == e {
|
if a == e {
|
||||||
return true
|
return true
|
||||||
|
@ -282,10 +283,11 @@ func contains(s []int, e int) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func removeListFromList(src, target []int) []int {
|
// RemoveIntListFromList removes all src's elements that are present in target
|
||||||
|
func removeIntListFromList(src, target []int) []int {
|
||||||
max := len(target)
|
max := len(target)
|
||||||
for i := 0; i < max; i++ {
|
for i := 0; i < max; i++ {
|
||||||
if contains(src, target[i]) {
|
if containsInt(src, target[i]) {
|
||||||
target = append(target[:i], target[i+1:]...)
|
target = append(target[:i], target[i+1:]...)
|
||||||
max--
|
max--
|
||||||
i--
|
i--
|
||||||
|
@ -359,7 +361,8 @@ func upgradePkgs(flags []string) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(repoNums) == 0 && len(aurNums) == 0 {
|
if len(repoNums) == 0 && len(aurNums) == 0 &&
|
||||||
|
(len(excludeRepo) > 0 || len(excludeAur) > 0) {
|
||||||
if len(repoUp) > 0 {
|
if len(repoUp) > 0 {
|
||||||
repoNums = BuildIntRange(0, len(repoUp)-1)
|
repoNums = BuildIntRange(0, len(repoUp)-1)
|
||||||
}
|
}
|
||||||
|
@ -367,9 +370,8 @@ func upgradePkgs(flags []string) error {
|
||||||
aurNums = BuildIntRange(0, len(aurUp)-1)
|
aurNums = BuildIntRange(0, len(aurUp)-1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
aurNums = removeListFromList(excludeAur, aurNums)
|
aurNums = removeIntListFromList(excludeAur, aurNums)
|
||||||
repoNums = removeListFromList(excludeRepo, repoNums)
|
repoNums = removeIntListFromList(excludeRepo, repoNums)
|
||||||
fmt.Println(repoNums, aurNums, excludeAur, excludeRepo)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(repoUp) != 0 {
|
if len(repoUp) != 0 {
|
||||||
|
|
Loading…
Reference in a new issue