get.go 1.8 KB

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