-
Notifications
You must be signed in to change notification settings - Fork 168
/
cmd.go
70 lines (64 loc) · 1.39 KB
/
cmd.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
* @Author: SpenserCai
* @Date: 2023-02-20 16:23:37
* @version:
* @LastEditors: SpenserCai
* @LastEditTime: 2023-02-24 12:41:40
* @Description: file content
*/
package main
import (
"fmt"
"strings"
prompt "github.com/c-bata/go-prompt"
)
var suggestions = []prompt.Suggest{
{Text: "show_info", Description: "获取微信基础信息"},
{Text: "decrypt", Description: "解密数据"},
{Text: "friends_list", Description: "获取好友列表"},
{Text: "help", Description: "帮助"},
{Text: "exit", Description: "退出程序"},
}
func completer(d prompt.Document) []prompt.Suggest {
w := d.GetWordBeforeCursor()
if w == "" {
return []prompt.Suggest{}
}
return prompt.FilterHasPrefix(suggestions, d.GetWordBeforeCursor(), true)
}
func executor(cmd string) {
cmd = strings.TrimSpace(cmd)
blocks := strings.Split(cmd, " ")
if len(blocks) == 0 {
return
}
switch blocks[0] {
case "show_info":
ShowInfoCmd()
case "decrypt":
DecryptCmd()
case "friends_list":
FriendsListCmd()
case "send_to_tg":
SendToTelegramCmd()
case "help":
// 显示命令的帮助信息
for _, v := range suggestions {
fmt.Println(v.Text, v.Description)
}
case "exit":
// 退出命令模式并关闭程序
return
default:
fmt.Println("Unknown command")
}
}
func RunCommand() {
p := prompt.New(
executor,
completer,
prompt.OptionPrefix(">>"),
prompt.OptionTitle("GoWxDump"),
)
p.Run()
}