mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-07 02:26:00 +08:00
cobra
This commit is contained in:
+3
-16
@@ -8,9 +8,6 @@ import (
|
||||
|
||||
type RootCmd struct {
|
||||
Command cobra.Command
|
||||
port int
|
||||
|
||||
prometheusPort int
|
||||
}
|
||||
|
||||
func NewRootCmd() (rootCmd *RootCmd) {
|
||||
@@ -20,8 +17,6 @@ func NewRootCmd() (rootCmd *RootCmd) {
|
||||
Short: "Start the server",
|
||||
Long: `Start the server`,
|
||||
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
|
||||
rootCmd.port = rootCmd.getPortFlag(cmd)
|
||||
rootCmd.prometheusPort = rootCmd.getPrometheusPortFlag(cmd)
|
||||
return rootCmd.getConfFromCmdAndInit(cmd)
|
||||
},
|
||||
}
|
||||
@@ -38,7 +33,7 @@ func (r *RootCmd) AddRunE(f func(cmd RootCmd) error) {
|
||||
|
||||
func (r *RootCmd) AddRpc(f func(port, prometheusPort int) error) {
|
||||
r.Command.RunE = func(cmd *cobra.Command, args []string) error {
|
||||
return f(r.port, r.prometheusPort)
|
||||
return f(r.getPortFlag(cmd), r.getPrometheusPortFlag(cmd))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,23 +50,15 @@ func (r *RootCmd) getPortFlag(cmd *cobra.Command) int {
|
||||
return port
|
||||
}
|
||||
|
||||
func (r *RootCmd) GetPortFlag() int {
|
||||
return r.port
|
||||
}
|
||||
|
||||
func (r *RootCmd) AddPrometheusPortFlag() {
|
||||
r.Command.Flags().StringP(constant.PrometheusPort, "pp", "", "server listen port")
|
||||
r.Command.Flags().StringP(constant.FlagPrometheusPort, "pp", "", "server prometheus listen port")
|
||||
}
|
||||
|
||||
func (r *RootCmd) getPrometheusPortFlag(cmd *cobra.Command) int {
|
||||
port, _ := cmd.Flags().GetInt(constant.PrometheusPort)
|
||||
port, _ := cmd.Flags().GetInt(constant.FlagPrometheusPort)
|
||||
return port
|
||||
}
|
||||
|
||||
func (r *RootCmd) GetPrometheusPortFlag() int {
|
||||
return r.prometheusPort
|
||||
}
|
||||
|
||||
func (r *RootCmd) getConfFromCmdAndInit(cmdLines *cobra.Command) error {
|
||||
configFolderPath, _ := cmdLines.Flags().GetString(constant.FlagConf)
|
||||
return config.InitConfig(configFolderPath)
|
||||
|
||||
Reference in New Issue
Block a user