mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-02 08:05:58 +08:00
test cobra
This commit is contained in:
+20
-2
@@ -1,13 +1,31 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"OpenIM/pkg/common/config"
|
||||
"OpenIM/pkg/common/constant"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func NewRootCmd() *cobra.Command {
|
||||
return &cobra.Command{
|
||||
type RootCmd 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()
|
||||
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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user