Files
open-im-server/pkg/common/cmd/root.go
T

32 lines
706 B
Go
Raw Normal View History

2023-03-07 12:12:16 +08:00
package cmd
import (
2023-03-07 17:59:34 +08:00
"OpenIM/pkg/common/config"
"OpenIM/pkg/common/constant"
2023-03-07 12:12:16 +08:00
"github.com/spf13/cobra"
)
2023-03-07 17:59:34 +08:00
type RootCmd cobra.Command
func NewRootCmd() RootCmd {
c := cobra.Command{
2023-03-07 12:12:16 +08:00
Use: "start",
Short: "Start the server",
Long: `Start the server`,
2023-03-07 17:59:34 +08:00
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
return getConfFromCmdAndInit(cmd)
},
2023-03-07 12:12:16 +08:00
}
2023-03-07 17:59:34 +08:00
c.Flags()
return RootCmd(c)
}
func (r RootCmd) Init() {
cobra.Command(r).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)
2023-03-07 12:12:16 +08:00
}