All checks were successful
ci/woodpecker/push/build Pipeline was successful
Signed-off-by: Nikolai Rodionov <iam@allanger.xyz>
39 lines
774 B
Go
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
|
|
}
|