forked from mcuadros/ofelia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ofelia.go
40 lines (32 loc) · 1.03 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
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 _, ok := err.(*flags.Error); ok {
parser.WriteHelp(os.Stdout)
fmt.Printf("\nBuild information\n commit: %s\n date:%s\n", version, build)
}
os.Exit(1)
}
}