forked from mcuadros/ofelia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ofelia.go
44 lines (35 loc) · 1.09 KB
/
ofelia.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
package main
import (
"fmt"
"os"
"github.com/jessevdk/go-flags"
"github.com/netresearch/ofelia/cli"
"github.com/netresearch/ofelia/core"
"github.com/op/go-logging"
)
var version string
var build string
const logFormat = "%{time} %{color} %{shortfile} ▶ %{level} %{color:reset} %{message}"
func buildLogger() core.Logger {
stdout := logging.NewLogBackend(os.Stdout, "", 0)
// Set the backends to be used.
logging.SetBackend(stdout)
logging.SetFormatter(logging.MustStringFormatter(logFormat))
return logging.MustGetLogger("ofelia")
}
func main() {
logger := buildLogger()
parser := flags.NewNamedParser("ofelia", flags.Default)
parser.AddCommand("daemon", "daemon process", "", &cli.DaemonCommand{Logger: logger})
parser.AddCommand("validate", "validates the config file", "", &cli.ValidateCommand{Logger: logger})
if _, err := parser.Parse(); err != nil {
if flagErr, ok := err.(*flags.Error); ok {
if flagErr.Type == flags.ErrHelp {
return
}
parser.WriteHelp(os.Stdout)
fmt.Printf("\nBuild information\n commit: %s\n date:%s\n", version, build)
}
os.Exit(1)
}
}