get.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. package main
  2. import (
  3. "fmt"
  4. "net/http"
  5. "os"
  6. "strings"
  7. "github.com/leonelquinteros/gotext"
  8. "github.com/Jguer/yay/v10/pkg/download"
  9. "github.com/Jguer/yay/v10/pkg/settings"
  10. "github.com/Jguer/yay/v10/pkg/settings/parser"
  11. "github.com/Jguer/yay/v10/pkg/text"
  12. )
  13. // yay -Gp.
  14. func printPkgbuilds(dbExecutor download.DBSearcher, httpClient *http.Client, targets []string,
  15. mode parser.TargetMode, aurURL string) error {
  16. pkgbuilds, err := download.PKGBUILDs(dbExecutor, httpClient, targets, aurURL, mode)
  17. if err != nil {
  18. text.Errorln(err)
  19. }
  20. if len(pkgbuilds) != 0 {
  21. for target, pkgbuild := range pkgbuilds {
  22. fmt.Printf("\n\n# %s\n\n", target)
  23. fmt.Print(string(pkgbuild))
  24. }
  25. }
  26. if len(pkgbuilds) != len(targets) {
  27. missing := []string{}
  28. for _, target := range targets {
  29. if _, ok := pkgbuilds[target]; !ok {
  30. missing = append(missing, target)
  31. }
  32. }
  33. text.Warnln(gotext.Get("Unable to find the following packages:"), strings.Join(missing, ", "))
  34. return fmt.Errorf("")
  35. }
  36. return nil
  37. }
  38. // yay -G.
  39. func getPkgbuilds(dbExecutor download.DBSearcher, config *settings.Configuration, targets []string,
  40. force bool) error {
  41. wd, err := os.Getwd()
  42. if err != nil {
  43. return err
  44. }
  45. cloned, errD := download.PKGBUILDRepos(dbExecutor,
  46. config.Runtime.CmdBuilder, targets, config.Runtime.Mode, config.AURURL, wd, force)
  47. if errD != nil {
  48. text.Errorln(errD)
  49. }
  50. if len(targets) != len(cloned) {
  51. missing := []string{}
  52. for _, target := range targets {
  53. if _, ok := cloned[target]; !ok {
  54. missing = append(missing, target)
  55. }
  56. }
  57. text.Warnln(gotext.Get("Unable to find the following packages:"), strings.Join(missing, ", "))
  58. err = fmt.Errorf("")
  59. }
  60. return err
  61. }