2024-09-24 06:17:11 -04:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2024-11-20 06:09:04 -05:00
|
|
|
"pcgamedb/config"
|
|
|
|
"pcgamedb/server"
|
2024-09-24 06:17:11 -04:00
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
var serverCmd = &cobra.Command{
|
|
|
|
Use: "server",
|
|
|
|
Long: "Start API server",
|
|
|
|
Short: "Start API server",
|
|
|
|
Run: ServerRun,
|
|
|
|
}
|
|
|
|
|
|
|
|
type serverCommandConfig struct {
|
|
|
|
Port string
|
|
|
|
AutoCrawl bool
|
|
|
|
}
|
|
|
|
|
|
|
|
var serverCmdCfg serverCommandConfig
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
serverCmd.Flags().StringVarP(&serverCmdCfg.Port, "port", "p", "8080", "server port")
|
|
|
|
serverCmd.Flags().BoolVarP(&serverCmdCfg.AutoCrawl, "auto-crawl", "c", true, "enable auto crawl")
|
|
|
|
RootCmd.AddCommand(serverCmd)
|
|
|
|
}
|
|
|
|
|
|
|
|
func ServerRun(cmd *cobra.Command, args []string) {
|
|
|
|
if serverCmdCfg.AutoCrawl {
|
|
|
|
config.Config.Server.AutoCrawl = true
|
|
|
|
}
|
|
|
|
config.Config.Server.Port = serverCmdCfg.Port
|
|
|
|
server.Run()
|
|
|
|
}
|