trustwallet-assets/cmd/main.go

63 lines
1.5 KiB
Go
Raw Normal View History

package main
import (
"flag"
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"
"github.com/trustwallet/assets-go-libs/src/processor"
)
var (
2021-11-23 13:34:25 +00:00
configPath, root, script string
)
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-12-11 21:30:03 +00:00
assetfsProcessor := processor.NewService(fileStorage, validatorsService)
2021-11-23 13:34:25 +00:00
switch script {
2021-12-11 21:30:03 +00:00
case "checker":
err = assetfsProcessor.RunJob(paths, assetfsProcessor.Check)
case "fixer":
err = assetfsProcessor.RunJob(paths, assetfsProcessor.Fix)
case "updater-auto":
2021-12-09 18:55:31 +00:00
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.")
}
if err != nil {
log.WithError(err).Error()
}
}
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")
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)
}