Files
softplayer-backend/cmd/root.go
Nikolai Rodionov 99f9bb462f
All checks were successful
ci/woodpecker/push/build Pipeline was successful
A bit of refactoring and updates
Signed-off-by: Nikolai Rodionov <iam@allanger.xyz>
2026-05-11 11:57:17 +02:00

39 lines
774 B
Go

package cmd
import (
"context"
"errors"
"gitea.badhouseplants.net/softplayer/softplayer-backend/internal/helpers/logger"
"github.com/alecthomas/kong"
)
var CLI struct {
Server Server `cmd:"" help:"Start the grpc server"`
Migrate Migrate `cmd:"" help:"Run the database migrations"`
// Args
LogLevel string `env:"SOFTPLAYER_LOGLEVEL" default:"info"`
}
var ErrUnknownCommand = errors.New("unknown command")
func Run() error {
kongCtx := kong.Parse(&CLI)
ctx := logger.NewLogger(context.Background(), CLI.LogLevel)
switch kongCtx.Command() {
case "server":
if err := CLI.Server.Run(ctx); err != nil {
return err
}
case "migrate":
if err := CLI.Migrate.Run(ctx); err != nil {
return err
}
default:
return ErrUnknownCommand
}
return nil
}