query.go 817 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package aur
  2. import (
  3. "fmt"
  4. "github.com/jguer/yay/util"
  5. rpc "github.com/mikkeloscar/aur"
  6. )
  7. const aurURL = "https://aur.archlinux.org/rpc/?"
  8. // Query is a collection of Results
  9. type Query []rpc.Pkg
  10. func (q Query) Len() int {
  11. return len(q)
  12. }
  13. func (q Query) Less(i, j int) bool {
  14. if util.SortMode == util.BottomUp {
  15. return q[i].NumVotes < q[j].NumVotes
  16. }
  17. return q[i].NumVotes > q[j].NumVotes
  18. }
  19. func (q Query) Swap(i, j int) {
  20. q[i], q[j] = q[j], q[i]
  21. }
  22. // MissingPackage warns if the Query was unable to find a package
  23. func (q Query) MissingPackage(pkgS []string) {
  24. for _, depName := range pkgS {
  25. found := false
  26. for _, dep := range q {
  27. if dep.Name == depName {
  28. found = true
  29. break
  30. }
  31. }
  32. if !found {
  33. fmt.Println("\x1b[31mUnable to find", depName, "in AUR\x1b[0m")
  34. }
  35. }
  36. return
  37. }