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/settings"
  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, httpClient *http.Client, targets []string,
  17. mode parser.TargetMode, aurURL string,
  18. ) error {
  19. pkgbuilds, err := download.PKGBUILDs(dbExecutor, aurClient, httpClient, targets, aurURL, mode)
  20. if err != nil {
  21. text.Errorln(err)
  22. }
  23. if len(pkgbuilds) != 0 {
  24. for target, pkgbuild := range pkgbuilds {
  25. fmt.Printf("\n\n# %s\n\n", target)
  26. fmt.Print(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. text.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. config *settings.Configuration, 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. config.Runtime.CmdBuilder, targets, config.Mode, config.AURURL, wd, force)
  51. if errD != nil {
  52. text.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. text.Warnln(gotext.Get("Unable to find the following packages:"), " ", strings.Join(missing, ", "))
  62. err = fmt.Errorf("")
  63. }
  64. return err
  65. }