sorarebuddy/cmd/console/root.go

57 lines
1.2 KiB
Go

package main
import (
"git.lehouerou.net/laurent/sorare"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"git.lehouerou.net/laurent/sorarebuddy/cmd/common"
"git.lehouerou.net/laurent/sorarebuddy/model"
"git.lehouerou.net/laurent/sorarebuddy/sorare_utils"
)
var Cmd = &cobra.Command{
Use: "console",
Short: "console",
Long: `console`,
RunE: run,
PersistentPreRunE: common.CmdPreRunE,
}
func main() {
common.Start(Cmd)
}
func init() {
common.InitParams(Cmd)
}
func run(cmd *cobra.Command, _ []string) error {
//var wg conc.WaitGroup
ctx := cmd.Context()
s, ok := ctx.Value(common.SorareContextKey).(*sorare.Sorare)
if !ok {
return errors.New("sorare not found in context")
}
db, ok := ctx.Value(common.DbContextKey).(*model.Queries)
if !ok {
return errors.New("db not found in context")
}
us := sorare_utils.NewUpdateService(s, db)
err := us.InitSyncDatabase(ctx)
if err != nil {
return errors.Wrap(err, "initializing database")
}
// log.Debug().Msg("start sequence completed. waiting for shutdown request")
// <-ctx.Done()
// log.Debug().Msg("shutdown requested")
// wg.Wait()
// log.Debug().Msg("shutdown complete")
return nil
}