-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathmain.go
89 lines (81 loc) · 1.96 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
package main
import (
"fmt"
"os"
"github.com/GrupaPracuj/iislog-prometheus-exporter/config"
"github.com/GrupaPracuj/iislog-prometheus-exporter/logging"
"github.com/GrupaPracuj/iislog-prometheus-exporter/service"
"github.com/GrupaPracuj/iislog-prometheus-exporter/version"
"github.com/mitchellh/cli"
)
const defaultServiceName = "IISLogExporter"
func main() {
var serviceName string
if len(os.Args) < 3 {
serviceName = defaultServiceName
} else {
serviceName = os.Args[2]
}
c := cli.NewCLI(serviceName, version.Version)
c.Args = os.Args[1:]
c.HiddenCommands = []string{service.RunAsDaemonArg}
c.Commands = map[string]cli.CommandFactory{
"version": func() (cli.Command, error) {
return &versionCommand{
version: version.Version,
}, nil
},
"check-config": func() (cli.Command, error) {
_, confErr := config.LoadConfig()
if confErr != nil {
panic(confErr)
}
return &checkConfigCommand{}, nil
},
"debug": func() (cli.Command, error) {
cfg, confErr := config.LoadConfig()
if confErr != nil {
panic(confErr)
}
logger := logging.Init(cfg, true)
return &debugCommand{
serviceName: serviceName,
config: cfg,
logger: logger,
}, nil
},
"install": func() (cli.Command, error) {
return &installCommand{
serviceName: serviceName,
}, nil
},
"remove": func() (cli.Command, error) {
cfg, confErr := config.LoadConfig()
if confErr != nil {
panic(confErr)
}
logger := logging.Init(cfg, false)
return &removeCommand{
serviceName: serviceName,
config: cfg,
logger: logger,
}, nil
},
service.RunAsDaemonArg: func() (cli.Command, error) {
cfg, confErr := config.LoadConfig()
if confErr != nil {
panic(confErr)
}
logger := logging.Init(cfg, false)
return &daemonCommand{
config: cfg,
logger: logger,
}, nil
},
}
exitStatus, err := c.Run()
if err != nil {
fmt.Fprintln(os.Stderr, err.Error())
}
os.Exit(exitStatus)
}