test-errcode
wangchuxiao 2 years ago
parent 5dfda23ded
commit f0943276cb

@ -1,7 +1,7 @@
package cmd package cmd
type MsgUtilsCmd struct { type MsgUtilsCmd struct {
RootCmd *RootCmd
userID string userID string
userIDFlag bool userIDFlag bool

@ -15,13 +15,13 @@ type RootCmd struct {
prometheusPortFlag bool prometheusPortFlag bool
} }
func NewRootCmd() RootCmd { func NewRootCmd() *RootCmd {
c := cobra.Command{ c := cobra.Command{
Use: "start", Use: "start",
Short: "Start the server", Short: "Start the server",
Long: `Start the server`, Long: `Start the server`,
} }
rootCmd := RootCmd{} rootCmd := &RootCmd{}
c.PersistentPreRunE = func(cmd *cobra.Command, args []string) error { c.PersistentPreRunE = func(cmd *cobra.Command, args []string) error {
if rootCmd.portFlag { if rootCmd.portFlag {
rootCmd.port = rootCmd.getPortFlag(cmd) rootCmd.port = rootCmd.getPortFlag(cmd)
@ -31,8 +31,8 @@ func NewRootCmd() RootCmd {
} }
return rootCmd.getConfFromCmdAndInit(cmd) return rootCmd.getConfFromCmdAndInit(cmd)
} }
rootCmd.init()
rootCmd.Command = c rootCmd.Command = c
rootCmd.init()
return rootCmd return rootCmd
} }
@ -47,7 +47,7 @@ func (r *RootCmd) init() {
} }
func (r *RootCmd) AddPortFlag() { func (r *RootCmd) AddPortFlag() {
//r.Command.Flags().IntP(constant.FlagPort, "p", 0, "server listen port") r.Command.Flags().IntP(constant.FlagPort, "p", 0, "server listen port")
r.portFlag = true r.portFlag = true
} }

Loading…
Cancel
Save