get.go 1.6 KB

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