-
Notifications
You must be signed in to change notification settings - Fork 162
/
flags.go
164 lines (157 loc) · 3.96 KB
/
flags.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
package utils
import (
"github.com/anyswap/CrossChain-Bridge/log"
"github.com/urfave/cli/v2"
)
var (
// DataDirFlag --datadir
DataDirFlag = &cli.StringFlag{
Name: "datadir",
Usage: "data directory",
Value: "",
}
// ConfigFileFlag -c|--config
ConfigFileFlag = &cli.StringFlag{
Name: "config",
Aliases: []string{"c"},
Usage: "Specify config file",
}
// TokenPairsDirFlag --pairsdir
TokenPairsDirFlag = &cli.StringFlag{
Name: "pairsdir",
Usage: "Specify token pairs directory",
}
// LogFileFlag --log
LogFileFlag = &cli.StringFlag{
Name: "log",
Usage: "Specify log file, support rotate",
}
// LogRotationFlag --rotate
LogRotationFlag = &cli.Uint64Flag{
Name: "rotate",
Usage: "log rotation time (unit hour)",
Value: 24,
}
// LogMaxAgeFlag --maxage
LogMaxAgeFlag = &cli.Uint64Flag{
Name: "maxage",
Usage: "log max age (unit hour)",
Value: 720,
}
// VerbosityFlag -v|--verbosity
VerbosityFlag = &cli.Uint64Flag{
Name: "verbosity",
Aliases: []string{"v"},
Usage: "log verbosity (0:panic, 1:fatal, 2:error, 3:warn, 4:info, 5:debug, 6:trace)",
Value: 4,
}
// JSONFormatFlag --json
JSONFormatFlag = &cli.BoolFlag{
Name: "json",
Usage: "output log in json format",
}
// ColorFormatFlag --color
ColorFormatFlag = &cli.BoolFlag{
Name: "color",
Usage: "output log in color text format",
Value: true,
}
// StartHeightFlag --start
StartHeightFlag = &cli.Uint64Flag{
Name: "start",
Usage: "start height (start inclusive)",
}
// EndHeightFlag --end
EndHeightFlag = &cli.Uint64Flag{
Name: "end",
Usage: "end height (end exclusive)",
}
// StableHeightFlag --stable
StableHeightFlag = &cli.Uint64Flag{
Name: "stable",
Usage: "stable height",
Value: 5,
}
// JobsFlag --jobs
JobsFlag = &cli.Uint64Flag{
Name: "jobs",
Usage: "number of jobs",
Value: 4,
}
// GatewayFlag --gateway
GatewayFlag = &cli.StringFlag{
Name: "gateway",
Usage: "gateway URL to connect",
}
// SwapServerFlag --swapserver
SwapServerFlag = &cli.StringFlag{
Name: "swapserver",
Usage: "swap server RPC address",
}
// DcrmAddressFlag --dcrmAddress
DcrmAddressFlag = &cli.StringFlag{
Name: "dcrmAddress",
Usage: "dcrm address",
}
// DepositAddressSliceFlag --deposit
DepositAddressSliceFlag = &cli.StringSliceFlag{
Name: "deposit",
Usage: "deposit address slice",
}
// DepositAddressFlag --deposit
DepositAddressFlag = &cli.StringFlag{
Name: "deposit",
Usage: "deposit address",
}
// TokenAddressSliceFlag --token
TokenAddressSliceFlag = &cli.StringSliceFlag{
Name: "token",
Usage: "token address slice",
}
// PairIDSliceFlag --pairid
PairIDSliceFlag = &cli.StringSliceFlag{
Name: "pairid",
Usage: "token pair id slice",
}
// KeystoreFileFlag --keystore
KeystoreFileFlag = &cli.StringFlag{
Name: "keystore",
Usage: "keystore file",
}
// PasswordFileFlag --password
PasswordFileFlag = &cli.StringFlag{
Name: "password",
Usage: "password file",
}
// SwapTypeFlag --swaptype
SwapTypeFlag = &cli.StringFlag{
Name: "swaptype",
Usage: "value can be swapin or swapout",
Value: "swapin",
}
)
// SetLogger set log level, json format, color, rotate ...
func SetLogger(ctx *cli.Context) {
logLevel := ctx.Uint64(VerbosityFlag.Name)
jsonFormat := ctx.Bool(JSONFormatFlag.Name)
colorFormat := ctx.Bool(ColorFormatFlag.Name)
log.SetLogger(uint32(logLevel), jsonFormat, colorFormat)
logFile := ctx.String(LogFileFlag.Name)
if logFile != "" {
logRotation := ctx.Uint64(LogRotationFlag.Name)
logMaxAge := ctx.Uint64(LogMaxAgeFlag.Name)
log.SetLogFile(logFile, logRotation, logMaxAge)
}
}
// GetDataDir specified by `--datadir`
func GetDataDir(ctx *cli.Context) string {
return ctx.String(DataDirFlag.Name)
}
// GetConfigFilePath specified by `-c|--config`
func GetConfigFilePath(ctx *cli.Context) string {
return ctx.String(ConfigFileFlag.Name)
}
// GetTokenPairsDir specified by `--pairsdir`
func GetTokenPairsDir(ctx *cli.Context) string {
return ctx.String(TokenPairsDirFlag.Name)
}