mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-06 04:15:46 +08:00
test cobra
This commit is contained in:
parent
c1746fb32e
commit
2c91185102
@ -93,15 +93,16 @@ var clearCmd = &cobra.Command{
|
||||
}
|
||||
|
||||
func main() {
|
||||
cmd.RootCmd.PersistentFlags().StringP("userID", "u", "", "openIM userID")
|
||||
cmd.RootCmd.PersistentFlags().StringP("groupID", "u", "", "openIM superGroupID")
|
||||
rootCmd := cmd.NewMsgUtilsCmd()
|
||||
rootCmd.Command.PersistentFlags().StringP("userID", "u", "", "openIM userID")
|
||||
rootCmd.Command.PersistentFlags().StringP("groupID", "u", "", "openIM superGroupID")
|
||||
seqCmd.Flags().BoolP("fixAll", "c", false, "openIM fix all seqs")
|
||||
msgCmd.Flags().BoolP("clearAll", "c", false, "openIM clear all timeout msgs")
|
||||
cmd.RootCmd.AddCommand(getCmd, fixCmd, clearCmd)
|
||||
getCmd.AddCommand(seqCmd, msgCmd)
|
||||
fixCmd.AddCommand(seqCmd)
|
||||
clearCmd.AddCommand(msgCmd)
|
||||
if err := cmd.RootCmd.Execute(); err != nil {
|
||||
rootCmd.AddCommand(getCmd, fixCmd, clearCmd)
|
||||
if err := rootCmd.Execute(); err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
42
pkg/common/cmd/msg.go
Normal file
42
pkg/common/cmd/msg.go
Normal file
@ -0,0 +1,42 @@
|
||||
package cmd
|
||||
|
||||
type MsgUtilsCmd struct {
|
||||
RootCmd
|
||||
userID string
|
||||
userIDFlag bool
|
||||
|
||||
superGroupID string
|
||||
superGroupIDFlag bool
|
||||
|
||||
clearAll bool
|
||||
clearAllFlag bool
|
||||
|
||||
fixAll bool
|
||||
fixAllFlag bool
|
||||
}
|
||||
|
||||
func NewMsgUtilsCmd() MsgUtilsCmd {
|
||||
return MsgUtilsCmd{RootCmd: NewRootCmd()}
|
||||
}
|
||||
|
||||
func (m *MsgUtilsCmd) AddUserIDFlag() {
|
||||
m.Command.PersistentFlags().StringP("userID", "u", "", "openIM userID")
|
||||
m.userIDFlag = true
|
||||
}
|
||||
|
||||
func (m *MsgUtilsCmd) getUserIDFlag() {
|
||||
m.Command.PersistentFlags().StringP("userID", "u", "", "openIM userID")
|
||||
|
||||
}
|
||||
|
||||
func (m *MsgUtilsCmd) AddGroupIDFlag() {
|
||||
m.Command.PersistentFlags().StringP("super-groupID", "u", "", "openIM superGroupID")
|
||||
}
|
||||
|
||||
func (m *MsgUtilsCmd) AddClearAllFlag() {
|
||||
m.Command.PersistentFlags().BoolP("clearAll", "c", false, "openIM clear all timeout msgs")
|
||||
}
|
||||
|
||||
func (m *MsgUtilsCmd) AddFixAllFlag() {
|
||||
m.Command.PersistentFlags().BoolP("fixAll", "c", false, "openIM fix all seqs")
|
||||
}
|
@ -27,7 +27,7 @@ func NewRootCmd() RootCmd {
|
||||
rootCmd.port = rootCmd.getPortFlag(cmd)
|
||||
}
|
||||
if rootCmd.prometheusPortFlag {
|
||||
rootCmd.prometheusPort = rootCmd.GetPrometheusPortFlag(cmd)
|
||||
rootCmd.prometheusPort = rootCmd.getPrometheusPortFlag(cmd)
|
||||
}
|
||||
return rootCmd.getConfFromCmdAndInit(cmd)
|
||||
}
|
||||
@ -47,7 +47,7 @@ func (r *RootCmd) init() {
|
||||
}
|
||||
|
||||
func (r *RootCmd) AddPortFlag() {
|
||||
r.Command.Flags().StringP(constant.FlagPort, "p", "", "server listen port")
|
||||
r.Command.Flags().IntP(constant.FlagPort, "p", 0, "server listen port")
|
||||
r.portFlag = true
|
||||
}
|
||||
|
||||
@ -65,7 +65,7 @@ func (r *RootCmd) AddPrometheusPortFlag() {
|
||||
r.prometheusPortFlag = true
|
||||
}
|
||||
|
||||
func (r *RootCmd) GetPrometheusPortFlag(cmd *cobra.Command) int {
|
||||
func (r *RootCmd) getPrometheusPortFlag(cmd *cobra.Command) int {
|
||||
port, _ := cmd.Flags().GetInt(constant.PrometheusPort)
|
||||
return port
|
||||
}
|
||||
@ -78,3 +78,7 @@ func (r *RootCmd) getConfFromCmdAndInit(cmdLines *cobra.Command) error {
|
||||
func (r *RootCmd) Execute() error {
|
||||
return r.Command.Execute()
|
||||
}
|
||||
|
||||
func (r *RootCmd) AddCommand(cmds ...*cobra.Command) {
|
||||
r.Command.AddCommand(cmds...)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user