get.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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) error {
  17. pkgbuilds, err := download.PKGBUILDs(dbExecutor, httpClient, targets, aurURL, mode)
  18. if err != nil {
  19. text.Errorln(err)
  20. }
  21. if len(pkgbuilds) != 0 {
  22. for target, pkgbuild := range pkgbuilds {
  23. fmt.Printf("\n\n# %s\n\n", target)
  24. fmt.Print(string(pkgbuild))
  25. }
  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. text.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,
  41. config *settings.Configuration, targets []string, force bool) error {
  42. wd, err := os.Getwd()
  43. if err != nil {
  44. return err
  45. }
  46. cloned, errD := download.PKGBUILDRepos(ctx, dbExecutor,
  47. config.Runtime.CmdBuilder, targets, config.Runtime.Mode, config.AURURL, wd, force)
  48. if errD != nil {
  49. text.Errorln(errD)
  50. }
  51. if len(targets) != len(cloned) {
  52. missing := []string{}
  53. for _, target := range targets {
  54. if _, ok := cloned[target]; !ok {
  55. missing = append(missing, target)
  56. }
  57. }
  58. text.Warnln(gotext.Get("Unable to find the following packages:"), strings.Join(missing, ", "))
  59. err = fmt.Errorf("")
  60. }
  61. return err
  62. }