This commit is contained in:
wangchuxiao
2023-03-13 12:34:56 +08:00
parent 9645d16b2d
commit 9fcfdc9fab
24 changed files with 146 additions and 146 deletions
+11 -11
View File
@@ -3,23 +3,29 @@ package cmd
import (
"OpenIM/pkg/common/config"
"OpenIM/pkg/common/constant"
"OpenIM/pkg/common/log"
"fmt"
"github.com/spf13/cobra"
)
type RootCmd struct {
Command cobra.Command
Name string
port int
prometheusPort int
}
func NewRootCmd() (rootCmd *RootCmd) {
rootCmd = &RootCmd{}
func NewRootCmd(name string) (rootCmd *RootCmd) {
rootCmd = &RootCmd{Name: name}
c := cobra.Command{
Use: "start",
Short: "Start the server",
Long: `Start the server`,
Short: fmt.Sprintf(`Start %s server`, name),
Long: fmt.Sprintf(`Start %s server`, name),
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
return rootCmd.getConfFromCmdAndInit(cmd)
if err := rootCmd.getConfFromCmdAndInit(cmd); err != nil {
return err
}
return log.InitFromConfig(name)
},
}
rootCmd.Command = c
@@ -27,12 +33,6 @@ func NewRootCmd() (rootCmd *RootCmd) {
return rootCmd
}
func (r *RootCmd) SetDesc(use, short, long string) {
r.Command.Use = use
r.Command.Short = short
r.Command.Long = long
}
func (r *RootCmd) addConfFlag() {
r.Command.Flags().StringP(constant.FlagConf, "c", "", "Path to config file folder")
}