blasphem/pkg/cmd/serve/cmd.go

49 lines
805 B
Go
Raw Permalink Normal View History

2022-09-25 11:42:36 -04:00
package serve
import (
"dynatron.me/x/blasphem/internal/common"
"dynatron.me/x/blasphem/pkg/config"
"dynatron.me/x/blasphem/pkg/server"
"github.com/spf13/cobra"
)
type ServeOptions struct {
cfg *config.Config
}
func Command(cfg *config.Config) *cobra.Command {
opts := makeOptions(cfg)
serveCmd := &cobra.Command{
2022-09-26 15:00:21 -04:00
Use: "serve",
2022-09-25 11:42:36 -04:00
Short: "starts the " + common.AppName + " server",
2022-09-26 15:00:21 -04:00
RunE: common.RunE(opts),
2022-09-25 11:42:36 -04:00
}
return serveCmd
}
func makeOptions(cfg *config.Config) *ServeOptions {
return &ServeOptions{
cfg: cfg,
}
}
func (o *ServeOptions) Options(_ *cobra.Command, args []string) error {
return nil
}
func (o *ServeOptions) Execute() error {
server, err := server.New(o.cfg)
if err != nil {
return err
}
err = server.Go()
if err != nil {
return err
}
return nil
}