2021-11-22 20:34:56 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
2021-11-24 11:03:46 +00:00
|
|
|
"os"
|
2021-11-22 20:34:56 +00:00
|
|
|
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
|
|
|
|
"github.com/trustwallet/assets-go-libs/pkg/file"
|
|
|
|
"github.com/trustwallet/assets-go-libs/src/config"
|
2021-12-09 18:55:31 +00:00
|
|
|
"github.com/trustwallet/assets-go-libs/src/core"
|
2021-11-22 20:34:56 +00:00
|
|
|
"github.com/trustwallet/assets-go-libs/src/processor"
|
2021-11-23 13:34:25 +00:00
|
|
|
"github.com/trustwallet/assets-go-libs/src/reporter"
|
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 {
|
|
|
|
log.WithError(err).Fatal("failed to load file structure")
|
|
|
|
}
|
|
|
|
|
2021-12-09 18:55:31 +00:00
|
|
|
fileStorage := file.NewService()
|
|
|
|
validatorsService := core.NewService(fileStorage)
|
2021-11-23 13:34:25 +00:00
|
|
|
reportService := reporter.NewReportService()
|
|
|
|
assetfsProcessor := processor.NewService(fileStorage, validatorsService, reportService)
|
|
|
|
|
|
|
|
switch script {
|
|
|
|
case "sanity-check":
|
|
|
|
err = assetfsProcessor.RunSanityCheck(paths)
|
2021-12-09 18:55:31 +00:00
|
|
|
case "update-auto":
|
|
|
|
err = assetfsProcessor.RunUpdateAuto()
|
2021-11-23 13:34:25 +00:00
|
|
|
default:
|
|
|
|
log.Error("Nothing to launch. Use --script flag to choose a script to run.")
|
|
|
|
}
|
|
|
|
|
2021-11-22 20:34:56 +00:00
|
|
|
if err != nil {
|
|
|
|
log.WithError(err).Error()
|
|
|
|
}
|
2021-11-23 13:34:25 +00:00
|
|
|
|
|
|
|
reports := reportService.GetReports()
|
|
|
|
for key, report := range reports {
|
|
|
|
log.WithFields(log.Fields{
|
|
|
|
"total_files": report.TotalFiles,
|
|
|
|
"errors": report.Errors,
|
|
|
|
"warnings": report.Warnings,
|
|
|
|
"fixed": report.Fixed,
|
|
|
|
}).Info(key)
|
2021-11-24 11:03:46 +00:00
|
|
|
|
|
|
|
if report.Errors > 0 {
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
2021-11-23 13:34:25 +00:00
|
|
|
}
|
2021-11-24 11:03:46 +00:00
|
|
|
|
2021-11-22 20:34:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func setup() {
|
2021-11-23 13:34:25 +00:00
|
|
|
flag.StringVar(&configPath, "config", "", "path to config file")
|
|
|
|
flag.StringVar(&root, "root", "./", "path to the root of the dir")
|
|
|
|
flag.StringVar(&script, "script", "", "script type to run")
|
2021-11-22 20:34:56 +00:00
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
if err := config.SetConfig(configPath); err != nil {
|
|
|
|
log.WithError(err).Fatal("failed to set config")
|
|
|
|
}
|
|
|
|
|
|
|
|
logLevel, err := log.ParseLevel(config.Default.App.LogLevel)
|
|
|
|
if err != nil {
|
|
|
|
log.WithError(err).Fatal("failed to parse log level")
|
|
|
|
}
|
|
|
|
|
|
|
|
log.SetLevel(logLevel)
|
|
|
|
}
|