You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Open-IM-Server/cmd/cmdutils/main.go

109 lines
2.6 KiB

2 years ago
package main
import (
2 years ago
"OpenIM/internal/tools"
2 years ago
"OpenIM/pkg/common/cmd"
2 years ago
"context"
2 years ago
"fmt"
"github.com/spf13/cobra"
"os"
2 years ago
)
2 years ago
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
2 years ago
},
}
2 years ago
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
},
2 years ago
}
2 years ago
var getCmd = &cobra.Command{
Use: "get",
Short: "get operation",
}
2 years ago
2 years ago
var fixCmd = &cobra.Command{
Use: "fix",
Short: "fix seq operation",
}
2 years ago
2 years ago
var clearCmd = &cobra.Command{
Use: "clear",
Short: "clear operation",
2 years ago
}
func main() {
2 years ago
cmd.RootCmd.PersistentFlags().StringP("userID", "u", "", "openIM userID")
cmd.RootCmd.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 {
2 years ago
fmt.Println(err)
os.Exit(1)
}
}