From f0943276cb5499c2f84f60b5407629bac14eb05d Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Tue, 7 Mar 2023 20:39:07 +0800 Subject: [PATCH] test cobra --- pkg/common/cmd/msg.go | 2 +- pkg/common/cmd/root.go | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pkg/common/cmd/msg.go b/pkg/common/cmd/msg.go index c0dd0fc6d..d1725eb03 100644 --- a/pkg/common/cmd/msg.go +++ b/pkg/common/cmd/msg.go @@ -1,7 +1,7 @@ package cmd type MsgUtilsCmd struct { - RootCmd + *RootCmd userID string userIDFlag bool diff --git a/pkg/common/cmd/root.go b/pkg/common/cmd/root.go index 34f6c69c1..dd0ffec46 100644 --- a/pkg/common/cmd/root.go +++ b/pkg/common/cmd/root.go @@ -15,13 +15,13 @@ type RootCmd struct { prometheusPortFlag bool } -func NewRootCmd() RootCmd { +func NewRootCmd() *RootCmd { c := cobra.Command{ Use: "start", Short: "Start the server", Long: `Start the server`, } - rootCmd := RootCmd{} + rootCmd := &RootCmd{} c.PersistentPreRunE = func(cmd *cobra.Command, args []string) error { if rootCmd.portFlag { rootCmd.port = rootCmd.getPortFlag(cmd) @@ -31,8 +31,8 @@ func NewRootCmd() RootCmd { } return rootCmd.getConfFromCmdAndInit(cmd) } - rootCmd.init() rootCmd.Command = c + rootCmd.init() return rootCmd } @@ -47,7 +47,7 @@ func (r *RootCmd) init() { } 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 }