main.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. package main
  2. import (
  3. "context"
  4. "fmt"
  5. "os"
  6. "path/filepath"
  7. "github.com/Jguer/yay/v12/pkg/db/ialpm"
  8. "github.com/Jguer/yay/v12/pkg/dep"
  9. "github.com/Jguer/yay/v12/pkg/settings"
  10. "github.com/Jguer/yay/v12/pkg/settings/parser"
  11. "github.com/Jguer/yay/v12/pkg/text"
  12. "github.com/Jguer/aur/metadata"
  13. "github.com/leonelquinteros/gotext"
  14. "github.com/pkg/errors"
  15. )
  16. func handleCmd() error {
  17. config, err := settings.NewConfig(settings.GetConfigPath(), "")
  18. if err != nil {
  19. return err
  20. }
  21. cmdArgs := parser.MakeArguments()
  22. if errP := config.ParseCommandLine(cmdArgs); errP != nil {
  23. return errP
  24. }
  25. pacmanConf, _, err := settings.RetrievePacmanConfig(cmdArgs, config.PacmanConf)
  26. if err != nil {
  27. return err
  28. }
  29. dbExecutor, err := ialpm.NewExecutor(pacmanConf, text.GlobalLogger)
  30. if err != nil {
  31. return err
  32. }
  33. aurCache, err := metadata.New(
  34. metadata.WithCacheFilePath(
  35. filepath.Join(config.BuildDir, "aur.json")))
  36. if err != nil {
  37. return errors.Wrap(err, gotext.Get("failed to retrieve aur Cache"))
  38. }
  39. grapher := dep.NewGrapher(dbExecutor, aurCache, true, settings.NoConfirm,
  40. cmdArgs.ExistsDouble("d", "nodeps"), false, false,
  41. config.Runtime.Logger.Child("grapher"))
  42. return graphPackage(context.Background(), grapher, cmdArgs.Targets)
  43. }
  44. func main() {
  45. if err := handleCmd(); err != nil {
  46. text.Errorln(err)
  47. os.Exit(1)
  48. }
  49. }
  50. func graphPackage(
  51. ctx context.Context,
  52. grapher *dep.Grapher,
  53. targets []string,
  54. ) error {
  55. if len(targets) != 1 {
  56. return errors.New(gotext.Get("only one target is allowed"))
  57. }
  58. graph, err := grapher.GraphFromAUR(ctx, nil, []string{targets[0]})
  59. if err != nil {
  60. return err
  61. }
  62. fmt.Fprintln(os.Stdout, graph.String())
  63. fmt.Fprintln(os.Stdout, "\nlayers map\n", graph.TopoSortedLayerMap(nil))
  64. return nil
  65. }