2022-09-06 23:25:44 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2022-11-08 01:32:21 +01:00
|
|
|
"context"
|
2022-09-06 23:25:44 +02:00
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
|
|
|
|
"github.com/Jguer/yay/v11/pkg/db/ialpm"
|
|
|
|
"github.com/Jguer/yay/v11/pkg/dep"
|
|
|
|
"github.com/Jguer/yay/v11/pkg/settings"
|
|
|
|
"github.com/Jguer/yay/v11/pkg/settings/parser"
|
|
|
|
"github.com/Jguer/yay/v11/pkg/text"
|
2022-11-15 15:44:50 +01:00
|
|
|
|
2022-11-16 00:25:17 +01:00
|
|
|
"github.com/Jguer/aur/metadata"
|
2022-09-06 23:25:44 +02:00
|
|
|
"github.com/leonelquinteros/gotext"
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
)
|
|
|
|
|
|
|
|
func handleCmd() error {
|
|
|
|
config, err := settings.NewConfig("")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
cmdArgs := parser.MakeArguments()
|
2022-11-15 15:44:50 +01:00
|
|
|
if errP := config.ParseCommandLine(cmdArgs); errP != nil {
|
|
|
|
return errP
|
2022-09-06 23:25:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
pacmanConf, _, err := settings.RetrievePacmanConfig(cmdArgs, config.PacmanConf)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
dbExecutor, err := ialpm.NewExecutor(pacmanConf)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-11-16 00:25:17 +01:00
|
|
|
aurCache, err := metadata.New(
|
|
|
|
metadata.WithCacheFilePath(
|
|
|
|
filepath.Join(config.BuildDir, "aur.json")))
|
2022-09-06 23:25:44 +02:00
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, gotext.Get("failed to retrieve aur Cache"))
|
|
|
|
}
|
|
|
|
|
2022-12-18 21:14:41 +01:00
|
|
|
grapher := dep.NewGrapher(dbExecutor, aurCache, true, settings.NoConfirm, os.Stdout, cmdArgs.ExistsDouble("d", "nodeps"), false)
|
2022-09-06 23:25:44 +02:00
|
|
|
|
2022-11-08 01:32:21 +01:00
|
|
|
return graphPackage(context.Background(), grapher, cmdArgs.Targets)
|
2022-09-06 23:25:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
if err := handleCmd(); err != nil {
|
|
|
|
text.Errorln(err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func graphPackage(
|
2022-11-08 01:32:21 +01:00
|
|
|
ctx context.Context,
|
2022-09-06 23:25:44 +02:00
|
|
|
grapher *dep.Grapher,
|
|
|
|
targets []string,
|
|
|
|
) error {
|
|
|
|
if len(targets) != 1 {
|
|
|
|
return errors.New(gotext.Get("only one target is allowed"))
|
|
|
|
}
|
|
|
|
|
2022-11-08 01:32:21 +01:00
|
|
|
graph, err := grapher.GraphFromAURCache(ctx, nil, []string{targets[0]})
|
2022-09-06 23:25:44 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Fprintln(os.Stdout, graph.String())
|
2022-12-18 02:00:39 +01:00
|
|
|
fmt.Fprintln(os.Stdout, "\nlayers\n", graph.TopoSortedLayers())
|
|
|
|
fmt.Fprintln(os.Stdout, "\ninverted order\n", graph.TopoSorted())
|
|
|
|
fmt.Fprintln(os.Stdout, "\nlayers map\n", graph.TopoSortedLayerMap())
|
2022-09-06 23:25:44 +02:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|