-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
112 lines (107 loc) · 2.42 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package main
import (
"io"
"os"
"github.com/perchnet/gomox/cmd"
"github.com/sirupsen/logrus"
easy "github.com/t-tomalak/logrus-easy-formatter"
"github.com/urfave/cli/v2"
)
func main() {
app := &cli.App{
Name: "gomox",
Usage: "gomox",
Commands: cmd.Commands(),
Flags: []cli.Flag{
&cli.StringFlag{
Name: "pveuser",
Aliases: []string{"u"},
Value: "",
Usage: "Proxmox VE username",
EnvVars: []string{"PVE_USER"},
},
&cli.StringFlag{
Name: "pvepassword",
Aliases: []string{"p"},
Value: "",
Usage: "Proxmox VE password",
EnvVars: []string{"PVE_PASSWORD"},
},
&cli.StringFlag{
Name: "pverealm",
Aliases: []string{"r"},
Value: "",
Usage: "Proxmox VE authentication realm",
EnvVars: []string{"PVE_REALM"},
},
&cli.StringFlag{
Name: "pveurl",
Usage: "Proxmox VE API URL",
Value: "", // https://127.0.0.1:8006/api2/json",
EnvVars: []string{"PVE_URL"},
},
&cli.StringFlag{
Name: "scheme",
Value: "https",
Usage: "API connection scheme (http or https)",
EnvVars: []string{"PVE_URI_SCHEME"},
},
&cli.StringFlag{
Name: "pvehost",
Aliases: []string{"a"},
Value: "127.0.0.1",
Usage: "Proxmox VE hostname/IP address",
EnvVars: []string{"PVE_HOST"},
},
&cli.UintFlag{
Name: "pveport",
Value: 8006,
Usage: "Proxmox VE API port",
EnvVars: []string{"PVE_PORT"},
},
&cli.BoolFlag{
Name: "debug",
Aliases: []string{"d"},
Usage: "Turn on verbose debug logging",
EnvVars: []string{"DEBUG"},
},
&cli.BoolFlag{
Name: "quiet",
Aliases: []string{"q"},
Usage: "Turn on off all logging",
},
&cli.BoolFlag{
Name: "wait",
Usage: "Wait for task completion.",
Category: "wait",
Aliases: []string{
"watch", "w",
"tail",
"follow", "f",
// I always forget what arg does that in a given cli app...
// so I'll just sort of let you pick which keyword to use :)
},
},
},
Before: func(ctx *cli.Context) error {
if ctx.Bool("debug") {
logrus.SetLevel(logrus.TraceLevel)
} else {
// treat logrus like fmt.Print
logrus.SetFormatter(
&easy.Formatter{
LogFormat: "%msg%",
},
)
}
if ctx.Bool("quiet") {
logrus.SetOutput(io.Discard)
}
return nil
},
}
err := app.Run(os.Args)
if err != nil {
logrus.Fatal(err)
}
}