This repository has been archived by the owner on Jun 1, 2023. It is now read-only.
/
run.go
61 lines (50 loc) · 1.83 KB
/
run.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
package cmd
import (
"flag"
"fmt"
log "github.com/sirupsen/logrus"
"github.com/suzuki-shunsuke/go-graylog"
"github.com/suzuki-shunsuke/go-graylog/mockserver/exec/usecase"
)
var help string
func init() {
help = fmt.Sprintf(`
graylog-mock-server - Run Graylog mock server.
USAGE:
graylog-mock-server [options]
VERSION:
%s
OPTIONS:
--port value port number. If you don't set this option, a free port is assigned and the assigned port number is output to the console when the mock server runs.
--log-level value the log level of logrus which the mock server uses internally. (default: "info")
--data value data file path. When the server runs data of the file is loaded and when data of the server is changed data is saved at the file. If this option is not set, no data is loaded and saved.
--help, -h show help
--version, -v print the version
`, graylog.Version)
}
// Run runs a mock server.
func Run() {
var portFlag = flag.Int(
"port", 0,
"port number. If you don't set this option, a free port is assigned and the assigned port number is output to the console when the mock server runs.")
var dataFlag = flag.String(
"data", "",
"data file path. When the server runs data of the file is loaded and when data of the server is changed data is saved at the file. If this option is not set, no data is loaded and saved.")
var logLevelFlag = flag.String(
"log-level", "info",
`the log level of logrus which the mock server uses internally. (default: "info")`)
var helpFlag = flag.Bool("help", false, "Show help.")
var versionFlag = flag.Bool("version", false, "Print the version.")
flag.Parse()
if *helpFlag {
fmt.Println(help)
return
}
if *versionFlag {
fmt.Println(graylog.Version)
return
}
if err := usecase.Run(*dataFlag, *logLevelFlag, *portFlag); err != nil {
log.Fatal(err)
}
}