2022-09-25 11:42:36 -04:00
|
|
|
package serve
|
|
|
|
|
|
|
|
import (
|
|
|
|
"dynatron.me/x/blasphem/internal/common"
|
2022-12-20 13:16:30 -05:00
|
|
|
"dynatron.me/x/blasphem/pkg/blas"
|
2022-09-25 11:42:36 -04:00
|
|
|
"dynatron.me/x/blasphem/pkg/server"
|
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
type ServeOptions struct {
|
2022-12-20 13:16:30 -05:00
|
|
|
core blas.Core
|
2022-09-25 11:42:36 -04:00
|
|
|
}
|
|
|
|
|
2022-12-20 13:16:30 -05:00
|
|
|
func Command(core blas.Core) *cobra.Command {
|
|
|
|
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 13:16:30 -05:00
|
|
|
func makeOptions(core blas.Core) *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
|
|
|
|
}
|