package cmd

import (
	"github.com/Jaculabilis/intake/web"
	"github.com/spf13/cobra"
)

var serveCmd = &cobra.Command{
	Use:   "serve",
	Short: "Serve the web interface",
	Long: `Serve the intake web interface.
`,
	Run: func(cmd *cobra.Command, args []string) {
		serve()
	},
}

var serveAddr string
var servePort string

func init() {
	rootCmd.AddCommand(serveCmd)

	serveCmd.Flags().StringVarP(&serveAddr, "addr", "a", "localhost", "Address to bind to")
	serveCmd.Flags().StringVarP(&servePort, "port", "p", "8081", "Port to bind to")
}

func serve() {
	db := openAndMigrateDb()
	web.RunServer(db, serveAddr, servePort)
}