forked from ztelliot/taierspeed-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
203 lines (195 loc) · 5.58 KB
/
main.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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
package main
import (
"os"
log "github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
"github.com/ztelliot/taierspeed-cli/defs"
"github.com/ztelliot/taierspeed-cli/speedtest"
)
// init sets up the essential bits on start up
func init() {
// set logrus formatter and default log level
formatter := &defs.NoFormatter{}
// debug level is for --debug messages
// info level is for non-suppress mode
// warn level is for suppress modes
// error level is for errors
log.SetOutput(os.Stderr)
log.SetFormatter(formatter)
log.SetLevel(log.InfoLevel)
}
func main() {
// define cli options
app := &cli.App{
Name: "Taierspeed-cli",
Usage: "Test your Internet speed with TaierSpeed",
Action: speedtest.SpeedTest,
HideHelp: true,
Flags: []cli.Flag{
cli.HelpFlag,
&cli.BoolFlag{
Name: defs.OptionVersion,
Aliases: []string{defs.OptionVersionAlt},
Usage: "Show the version number and exit",
},
&cli.BoolFlag{
Name: defs.OptionCheckUpdate,
Aliases: []string{defs.OptionCheckUpdateAlt},
Usage: "Check for updates and exit",
},
&cli.BoolFlag{
Name: defs.OptionIPv4,
Aliases: []string{defs.OptionIPv4Alt},
Usage: "Force IPv4 only",
},
&cli.BoolFlag{
Name: defs.OptionIPv6,
Aliases: []string{defs.OptionIPv6Alt},
Usage: "Force IPv6 only",
},
&cli.BoolFlag{
Name: defs.OptionNoDownload,
Usage: "Do not perform download test",
Hidden: true,
},
&cli.BoolFlag{
Name: defs.OptionNoUpload,
Usage: "Do not perform upload test",
Hidden: true,
},
&cli.BoolFlag{
Name: defs.OptionNoICMP,
Usage: "Do not use ICMP ping. ICMP doesn't work well under Linux\n" +
"\tat this moment, so you might want to disable it\n\t",
},
&cli.IntFlag{
Name: defs.OptionConcurrent,
Aliases: []string{defs.OptionConcurrentAlt},
Usage: "Concurrent HTTP requests being made",
Value: 3,
},
&cli.BoolFlag{
Name: defs.OptionBytes,
Usage: "Display values in bytes instead of bits. Does not affect\n" +
"\toutput from --json or --csv",
},
&cli.BoolFlag{
Name: defs.OptionMebiBytes,
Usage: "Use 1024 bytes as 1 kilobyte instead of 1000\n\t",
},
&cli.BoolFlag{
Name: defs.OptionSimple,
Aliases: []string{defs.OptionSimpleAlt},
Usage: "Suppress verbose output, only show basic information\n\t",
},
&cli.BoolFlag{
Name: defs.OptionCSV,
Usage: "Suppress verbose output. Speeds listed in bit/s and not\n" +
"\taffected by --bytes",
},
&cli.StringFlag{
Name: defs.OptionCSVDelimiter,
Usage: "Single character delimiter to use in CSV output\n\t",
Value: ",",
},
&cli.BoolFlag{
Name: defs.OptionCSVHeader,
Usage: "Print CSV headers",
},
&cli.BoolFlag{
Name: defs.OptionJSON,
Usage: "Suppress verbose output. Speeds listed in bit/s and not\n" +
"\taffected by --bytes",
},
&cli.BoolFlag{
Name: defs.OptionList,
Aliases: []string{defs.OptionListAlt},
Usage: "Display a list of servers",
},
&cli.StringSliceFlag{
Name: defs.OptionServer,
Aliases: []string{defs.OptionServerAlt},
Usage: "Specify a server `ID` to test against. Can be supplied\n" +
"\tmultiple times",
},
&cli.StringSliceFlag{
Name: defs.OptionServerGroup,
Aliases: []string{defs.OptionServerGroupAlt},
Usage: "Specify a `GROUP` of servers by PROVINCE@ISP to test.\n" +
"\tCan be supplied multiple times.\n" +
"\tPROVINCE refer to `GB/T 2260-2007` (bj, sh, gd... etc).\n" +
"\tISP can be {ct, cu, cm, cernet, catv, drpeng} or `ASN`.\n" +
"\tYou can use `lo` to refer to the current province or ISP",
},
&cli.StringSliceFlag{
Name: defs.OptionExclude,
Usage: "`EXCLUDE` a server from selection. Can be supplied\n" +
"\tmultiple times",
},
&cli.StringFlag{
Name: defs.OptionSource,
Usage: "`SOURCE` IP address to bind to, will not obey when\n" +
"\tfetch server list",
},
&cli.StringFlag{
Name: defs.OptionInterface,
Aliases: []string{defs.OptionInterfaceAlt},
Usage: "Network `INTERFACE` to bind to, only available for linux",
},
&cli.IntFlag{
Name: defs.OptionTimeout,
Usage: "HTTP `TIMEOUT` in seconds",
Value: 15,
},
&cli.IntFlag{
Name: defs.OptionDuration,
Aliases: []string{defs.OptionDurationAlt},
Usage: "Upload and download test duration in seconds\n\t",
Value: 15,
Hidden: true,
},
&cli.IntFlag{
Name: defs.OptionUploadSize,
Usage: "Size of payload being uploaded in KiB",
Value: 1024,
Hidden: true,
},
&cli.BoolFlag{
Name: defs.OptionNoPreAllocate,
Usage: "Do not pre allocate upload data. Pre allocation is\n" +
"\tenabled by default to improve upload performance. To\n" +
"\tsupport systems with insufficient memory, use this\n" +
"\toption to avoid out of memory errors",
},
&cli.StringFlag{
Name: defs.OptionAPIBase,
Usage: "Core API `URL`",
Value: "https://speed.qwq.vc/api",
Hidden: true,
},
&cli.StringFlag{
Name: defs.OptionAPIVersion,
Usage: "Core API `VERSION`",
Value: "v1",
Hidden: true,
},
&cli.BoolFlag{
Name: defs.OptionTLSInsecure,
Usage: "Disable TLS certificate verification",
Value: false,
Hidden: true,
},
&cli.BoolFlag{
Name: defs.OptionDebug,
Aliases: []string{"verbose"},
Usage: "Debug mode (verbose logging)",
Hidden: true,
},
},
}
// run main function with cli options
err := app.Run(os.Args)
if err != nil {
log.Fatal("Terminated due to error")
}
}