get.go 1.7 KB

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