-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcomb.go
61 lines (51 loc) · 1.22 KB
/
comb.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 main
import (
"fmt"
log "github.com/Sirupsen/logrus"
comb "github.com/bingohuang/comb/cli"
"github.com/bingohuang/comb/version"
"github.com/codegangsta/cli"
"os"
"runtime"
)
func main() {
app := cli.NewApp()
app.Name = "comb"
app.Usage = `is a tool to manage CloudComb resources base on cloudcomb-go-sdk.`
app.Version = fmt.Sprintf("%s %s/%s %s", version.VERSION, runtime.GOOS,
runtime.GOARCH, runtime.Version())
app.Author = "Bingo Huang"
app.Email = "[email protected]"
// setup global flags
app.Flags = []cli.Flag{
cli.BoolFlag{
Name: "debug",
Usage: "debug mode",
EnvVar: "DEBUG",
},
cli.StringFlag{
Name: "log-level, l",
Value: "info",
Usage: fmt.Sprintf("Log level (options: debug, info, warn, error, fatal, panic)"),
},
}
// setup log level
app.Before = func(c *cli.Context) error {
log.SetOutput(os.Stderr)
level, err := log.ParseLevel(c.String("log-level"))
if err != nil {
log.Fatalf(err.Error())
}
log.SetLevel(level)
if !c.IsSet("log-level") && !c.IsSet("l") && c.Bool("debug") {
log.SetLevel(log.DebugLevel)
}
return nil
}
// setup commands
app.Commands = comb.Commands
// run app
if err := app.Run(os.Args); err != nil {
log.Fatal(err)
}
}