-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
53 lines (44 loc) · 1.16 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
// Package main initializes and starts ipman
package main
import (
"log/slog"
"os"
"strings"
// CLI library
"github.com/mitchellh/cli"
)
// log is a package global logger
var log *slog.Logger
// setupLogger configures the package global logger
func setupLogger() {
lvl := &slog.LevelVar{} // create new level logger
lvl.Set(slog.LevelInfo) // default to Info
log = slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: lvl}))
if l := os.Getenv("LOG"); l != "" {
switch {
case strings.HasPrefix(l, "D"):
lvl.Set(slog.LevelDebug)
case strings.HasPrefix(l, "W"):
lvl.Set(slog.LevelWarn)
case strings.HasPrefix(l, "E"):
lvl.Set(slog.LevelError)
}
}
}
// it all starts here
func main() {
var c *cli.CLI // cli object
var status int // exit status
var err error // general error holder
// setup logger
setupLogger()
// init and populate cli object
c = cli.NewCLI(appName, appVersion)
c.Args = os.Args[1:] // arguments minus command
c.Commands = initCommands() // see commands.go
// run command and check return
if status, err = c.Run(); err != nil {
log.Error("error executing CLI", "err", err)
}
os.Exit(status)
}