A bit of refactoring and updates
All checks were successful
ci/woodpecker/push/build Pipeline was successful
All checks were successful
ci/woodpecker/push/build Pipeline was successful
Signed-off-by: Nikolai Rodionov <iam@allanger.xyz>
This commit is contained in:
38
cmd/root.go
Normal file
38
cmd/root.go
Normal file
@@ -0,0 +1,38 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user