sorareranks/cmd/console/root.go

52 lines
1008 B
Go

package main
import (
"errors"
"git.lehouerou.net/laurent/sorare"
"github.com/rs/zerolog/log"
"github.com/sourcegraph/conc"
"github.com/spf13/cobra"
"github.com/uptrace/bun"
"git.lehouerou.net/laurent/sorareranks/cmd/common"
)
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()
_, ok := ctx.Value("sorare").(*sorare.Sorare)
if !ok {
return errors.New("sorare client not found in context")
}
_, ok = ctx.Value("db").(*bun.DB)
if !ok {
return errors.New("database not found in context")
}
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
}