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"
2022-12-20 16:26:04 -05:00
blas "dynatron.me/x/blasphem/pkg/blas/core"
2022-09-25 11:42:36 -04:00
"dynatron.me/x/blasphem/pkg/server"
"github.com/spf13/cobra"
)
type ServeOptions struct {
2022-12-20 19:05:45 -05:00
core blas.Blas
2022-09-25 11:42:36 -04:00
}
2022-12-20 19:05:45 -05:00
func Command(core blas.Blas) *cobra.Command {
2022-12-20 13:16:30 -05:00
opts := makeOptions(core)
2022-09-25 11:42:36 -04:00
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
}
2022-12-20 19:05:45 -05:00
func makeOptions(core blas.Blas) *ServeOptions {
2022-09-25 11:42:36 -04:00
return &ServeOptions{
2022-12-20 13:16:30 -05:00
core: core,
2022-09-25 11:42:36 -04:00
}
}
func (o *ServeOptions) Options(_ *cobra.Command, args []string) error {
return nil
}
func (o *ServeOptions) Execute() error {
2022-12-20 13:16:30 -05:00
server, err := server.New(o.core)
2022-09-25 11:42:36 -04:00
if err != nil {
return err
}
err = server.Go()
if err != nil {
return err
}
return nil
}