query.go 781 B

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