2021-11-22 20:34:56 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
|
2021-12-19 21:39:53 +00:00
|
|
|
"github.com/trustwallet/assets/internal/config"
|
|
|
|
"github.com/trustwallet/assets/internal/file"
|
|
|
|
"github.com/trustwallet/assets/internal/processor"
|
2021-12-23 19:30:20 +00:00
|
|
|
"github.com/trustwallet/assets/internal/report"
|
2021-12-19 21:39:53 +00:00
|
|
|
"github.com/trustwallet/assets/internal/service"
|
2021-11-22 20:34:56 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2021-11-23 13:34:25 +00:00
|
|
|
configPath, root, script string
|
2021-11-22 20:34:56 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
setup()
|
|
|
|
|
|
|
|
paths, err := file.ReadLocalFileStructure(root, config.Default.ValidatorsSettings.RootFolder.SkipFiles)
|
|
|
|
if err != nil {
|
2021-12-19 21:39:53 +00:00
|
|
|
log.WithError(err).Fatal("Failed to load file structure.")
|
2021-11-22 20:34:56 +00:00
|
|
|
}
|
|
|
|
|
2021-12-23 19:30:20 +00:00
|
|
|
fileService := file.NewService(paths...)
|
|
|
|
validatorsService := processor.NewService(fileService)
|
|
|
|
reportService := report.NewService()
|
|
|
|
assetfsProcessor := service.NewService(fileService, validatorsService, reportService)
|
2021-11-23 13:34:25 +00:00
|
|
|
|
|
|
|
switch script {
|
2021-12-11 21:30:03 +00:00
|
|
|
case "checker":
|
2021-12-19 21:39:53 +00:00
|
|
|
assetfsProcessor.RunJob(paths, assetfsProcessor.Check)
|
2021-12-11 21:30:03 +00:00
|
|
|
case "fixer":
|
2021-12-19 21:39:53 +00:00
|
|
|
assetfsProcessor.RunJob(paths, assetfsProcessor.Fix)
|
2021-12-11 21:30:03 +00:00
|
|
|
case "updater-auto":
|
2021-12-19 21:39:53 +00:00
|
|
|
assetfsProcessor.RunUpdateAuto()
|
|
|
|
case "updater-manual":
|
|
|
|
assetfsProcessor.RunUpdateManual()
|
2021-11-23 13:34:25 +00:00
|
|
|
default:
|
2021-12-13 18:29:16 +00:00
|
|
|
log.Info("Nothing to launch. Use --script flag to choose a script to run.")
|
2021-11-23 13:34:25 +00:00
|
|
|
}
|
2021-12-23 19:30:20 +00:00
|
|
|
|
|
|
|
reportMsg := reportService.GetReport()
|
|
|
|
|
|
|
|
if reportService.IsFailed() {
|
|
|
|
log.Fatal(reportMsg)
|
|
|
|
} else {
|
|
|
|
log.Info(reportMsg)
|
|
|
|
}
|
2021-11-22 20:34:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func setup() {
|
2021-12-19 21:39:53 +00:00
|
|
|
flag.StringVar(&configPath, "config", "./.github/assets.config.yaml", "path to config file")
|
2021-11-23 13:34:25 +00:00
|
|
|
flag.StringVar(&root, "root", "./", "path to the root of the dir")
|
|
|
|
flag.StringVar(&script, "script", "", "script type to run")
|
2021-12-19 21:39:53 +00:00
|
|
|
|
2021-11-22 20:34:56 +00:00
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
if err := config.SetConfig(configPath); err != nil {
|
2021-12-19 21:39:53 +00:00
|
|
|
log.WithError(err).Fatal("Failed to set config.")
|
2021-11-22 20:34:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
logLevel, err := log.ParseLevel(config.Default.App.LogLevel)
|
|
|
|
if err != nil {
|
2021-12-19 21:39:53 +00:00
|
|
|
log.WithError(err).Fatal("Failed to parse log level.")
|
2021-11-22 20:34:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
log.SetLevel(logLevel)
|
|
|
|
}
|