-
Notifications
You must be signed in to change notification settings - Fork 0
/
nebms.go
104 lines (95 loc) · 2.66 KB
/
nebms.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package main
import (
"govote/signer"
"govote/tool"
"govote/util"
"os"
"strings"
)
const helpString = `Command list.
# create key & signature
create Create a private key.
sign <file_path> Sign the data file.
# contract
contract <contract_config_file_path> Create contract.
# data
data delete <address> Create 'delete manager' data.
data add <address> Create 'add manager' data.
data replace <oldAddress> <newAddress> Create 'replace manager' data.
data send_nas <txs_file_path> Create 'send nas' data.
data update_send_nas_rule <send_nas_rule_file_path> Create 'update send nas signature rules' data.
data update_sys_config <sys_config_file_path> Create 'update sys config' data.
data merge <data_file1_path> <data_file2_path> ... Merge data file.
`
func checkArgsLen(length int) bool {
if len(os.Args) < length {
util.PrintError("param error. ")
return false
}
return true
}
func createData(dataType string) {
switch dataType {
case "delete":
if checkArgsLen(4) {
tool.CreateDeleteManagerData(os.Args[3])
}
case "add":
if checkArgsLen(4) {
tool.CreateAddManagerData(os.Args[3])
}
case "replace":
if checkArgsLen(5) {
tool.CreateReplaceManagerData(os.Args[3], os.Args[4])
}
case "send_nas":
if checkArgsLen(4) {
tool.CreateSendNasData(os.Args[3])
}
case "update_send_nas_rule":
if checkArgsLen(4) {
tool.CreateUpdateSendNasRuleData(os.Args[3])
}
case "update_sys_config":
if checkArgsLen(4) {
tool.CreateUpdateSysConfigData(os.Args[3])
}
case "merge":
if checkArgsLen(5) {
var files []string
for index, item := range os.Args {
if index > 2 {
files = append(files, item)
}
}
tool.MergeData(files)
}
}
}
func executeCmd(cmd string) {
switch strings.ToLower(strings.Trim(cmd, " ")) {
case "create":
signer.CreateKey()
case "sign":
if checkArgsLen(3) {
signer.Sign(os.Args[2], "", "")
}
case "contract":
if checkArgsLen(3) {
tool.CreateContract(os.Args[2])
}
case "data":
if checkArgsLen(3) {
createData(os.Args[2])
}
default:
util.Print("unknown cmd:", cmd)
}
}
func main() {
if len(os.Args) == 1 {
util.Print(helpString)
return
}
executeCmd(os.Args[1])
}