-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.go
56 lines (48 loc) · 1.04 KB
/
cli.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
package cli
import (
"os"
"github.com/urfave/cli"
)
type Application struct {
*cli.App
verbose bool
configFile string
}
func New() *Application {
app := &Application{App: cli.NewApp()}
app.Name = "rp"
app.Version = "0.0.1"
app.Usage = "reverse-proxy with weighted round-robin load-balancer."
app.Author = "Ahmadreza Zibaei (magicniko)"
app.Flags = []cli.Flag{
cli.BoolFlag{
EnvVar: "VERBOSE",
Name: "verbose",
Usage: "verbose log output",
Destination: &app.verbose,
},
cli.StringFlag{
Name: "config, c",
Usage: "load configuration from `FILE`",
Destination: &app.configFile,
},
}
app.Commands = []cli.Command{
{
Name: "serve",
Aliases: []string{"s"},
Usage: "Start reverse-proxy to serve on listen address",
Action: app.serve,
},
{
Name: "generate",
Aliases: []string{"g"},
Usage: "Generate a simple configuration file from template",
Action: app.generate,
},
}
return app
}
func (a *Application) Run() error {
return a.App.Run(os.Args)
}