mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-02 16:15:59 +08:00
test cobra
This commit is contained in:
+10
-96
@@ -1,108 +1,22 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"OpenIM/internal/tools"
|
||||
"OpenIM/pkg/common/cmd"
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/spf13/cobra"
|
||||
"os"
|
||||
)
|
||||
|
||||
var seqCmd = &cobra.Command{
|
||||
Use: "seq",
|
||||
Short: "seq operation",
|
||||
RunE: func(cmdLines *cobra.Command, args []string) error {
|
||||
msgTool, err := tools.InitMsgTool()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
userID, _ := cmdLines.Flags().GetString("userID")
|
||||
superGroupID, _ := cmdLines.Flags().GetString("superGroupID")
|
||||
fixAll, _ := cmdLines.Flags().GetBool("fixAll")
|
||||
ctx := context.Background()
|
||||
switch {
|
||||
case cmdLines.Parent() == getCmd:
|
||||
switch {
|
||||
case userID != "":
|
||||
msgTool.ShowUserSeqs(ctx, userID)
|
||||
case superGroupID != "":
|
||||
msgTool.ShowSuperGroupSeqs(ctx, superGroupID)
|
||||
}
|
||||
case cmdLines.Parent() == fixCmd:
|
||||
switch {
|
||||
case userID != "":
|
||||
_, _, err = msgTool.GetAndFixUserSeqs(ctx, userID)
|
||||
case superGroupID != "":
|
||||
err = msgTool.FixGroupSeq(ctx, userID)
|
||||
case fixAll:
|
||||
err = msgTool.FixAllSeq(ctx)
|
||||
}
|
||||
}
|
||||
return err
|
||||
},
|
||||
}
|
||||
|
||||
var msgCmd = &cobra.Command{
|
||||
Use: "msg",
|
||||
Short: "msg operation",
|
||||
RunE: func(cmdLines *cobra.Command, args []string) error {
|
||||
msgTool, err := tools.InitMsgTool()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
userID, _ := cmdLines.Flags().GetString("userID")
|
||||
superGroupID, _ := cmdLines.Flags().GetString("superGroupID")
|
||||
clearAll, _ := cmdLines.Flags().GetBool("clearAll")
|
||||
ctx := context.Background()
|
||||
switch {
|
||||
case cmdLines.Parent() == getCmd:
|
||||
switch {
|
||||
case userID != "":
|
||||
msgTool.ShowUserSeqs(ctx, userID)
|
||||
case superGroupID != "":
|
||||
msgTool.ShowSuperGroupSeqs(ctx, superGroupID)
|
||||
}
|
||||
case cmdLines.Parent() == clearCmd:
|
||||
switch {
|
||||
case userID != "":
|
||||
msgTool.ClearUsersMsg(ctx, []string{userID})
|
||||
case superGroupID != "":
|
||||
msgTool.ClearSuperGroupMsg(ctx, []string{superGroupID})
|
||||
case clearAll:
|
||||
msgTool.AllUserClearMsgAndFixSeq()
|
||||
}
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
var getCmd = &cobra.Command{
|
||||
Use: "get",
|
||||
Short: "get operation",
|
||||
}
|
||||
|
||||
var fixCmd = &cobra.Command{
|
||||
Use: "fix",
|
||||
Short: "fix seq operation",
|
||||
}
|
||||
|
||||
var clearCmd = &cobra.Command{
|
||||
Use: "clear",
|
||||
Short: "clear operation",
|
||||
}
|
||||
|
||||
func main() {
|
||||
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")
|
||||
getCmd.AddCommand(seqCmd, msgCmd)
|
||||
fixCmd.AddCommand(seqCmd)
|
||||
clearCmd.AddCommand(msgCmd)
|
||||
rootCmd.AddCommand(getCmd, fixCmd, clearCmd)
|
||||
if err := rootCmd.Execute(); err != nil {
|
||||
msgUtilsCmd := cmd.NewMsgUtilsCmd()
|
||||
msgUtilsCmd.AddSuperGroupIDFlag()
|
||||
msgUtilsCmd.AddUserIDFlag()
|
||||
seqCmd := cmd.NewSeqCmd()
|
||||
msgCmd := cmd.NewMsgCmd()
|
||||
cmd.GetCmd.AddCommand(seqCmd.Command, msgCmd.Command)
|
||||
cmd.FixCmd.AddCommand(seqCmd.Command)
|
||||
cmd.GetCmd.AddCommand(msgCmd.Command)
|
||||
msgUtilsCmd.AddCommand(cmd.GetCmd, cmd.FixCmd, cmd.ClearCmd)
|
||||
if err := msgUtilsCmd.Execute(); err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user