mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-06 04:15:46 +08:00
36 lines
764 B
Go
36 lines
764 B
Go
package cmd
|
|
|
|
import (
|
|
"OpenIM/pkg/common/config"
|
|
"OpenIM/pkg/common/constant"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
type RootCmd struct {
|
|
Command cobra.Command
|
|
}
|
|
|
|
func NewRootCmd() RootCmd {
|
|
c := cobra.Command{
|
|
Use: "start",
|
|
Short: "Start the server",
|
|
Long: `Start the server`,
|
|
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
|
|
return getConfFromCmdAndInit(cmd)
|
|
},
|
|
}
|
|
c.Flags()
|
|
rootCmd := RootCmd{Command: c}
|
|
rootCmd.init()
|
|
return rootCmd
|
|
}
|
|
|
|
func (r RootCmd) init() {
|
|
r.Command.Flags().StringP(constant.FlagConf, "c", "", "Path to config file folder")
|
|
}
|
|
|
|
func getConfFromCmdAndInit(cmdLines *cobra.Command) error {
|
|
configFolderPath, _ := cmdLines.Flags().GetString(constant.FlagConf)
|
|
return config.InitConfig(configFolderPath)
|
|
}
|