get.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. for target, pkgbuild := range pkgbuilds {
  25. logger.Printf("\n\n# %s\n\n%s", target, string(pkgbuild))
  26. }
  27. if len(pkgbuilds) != len(targets) {
  28. missing := []string{}
  29. for _, target := range targets {
  30. if _, ok := pkgbuilds[target]; !ok {
  31. missing = append(missing, target)
  32. }
  33. }
  34. logger.Warnln(gotext.Get("Unable to find the following packages:"), " ", strings.Join(missing, ", "))
  35. return fmt.Errorf("")
  36. }
  37. return nil
  38. }
  39. // yay -G.
  40. func getPkgbuilds(ctx context.Context, dbExecutor download.DBSearcher, aurClient aur.QueryClient,
  41. run *runtime.Runtime, targets []string, force bool,
  42. ) error {
  43. wd, err := os.Getwd()
  44. if err != nil {
  45. return err
  46. }
  47. cloned, errD := download.PKGBUILDRepos(ctx, dbExecutor, aurClient,
  48. run.CmdBuilder, run.Logger, targets, run.Cfg.Mode, run.Cfg.AURURL, wd, force)
  49. if errD != nil {
  50. run.Logger.Errorln(errD)
  51. }
  52. if len(targets) != len(cloned) {
  53. missing := []string{}
  54. for _, target := range targets {
  55. if _, ok := cloned[target]; !ok {
  56. missing = append(missing, target)
  57. }
  58. }
  59. run.Logger.Warnln(gotext.Get("Unable to find the following packages:"), " ", strings.Join(missing, ", "))
  60. err = fmt.Errorf("")
  61. }
  62. return err
  63. }