-
Notifications
You must be signed in to change notification settings - Fork 31
/
cli.go
60 lines (55 loc) · 1.44 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
57
58
59
60
package main
import (
"os"
"github.com/urfave/cli"
)
func initCLI() *CLI {
app := &CLI{}
app.config = &Config{}
app.logger = InitLogger(&LoggerConfig{
Name: "cli",
Format: "production",
Level: "trace",
})
app.rawLogger = InitLogger(&LoggerConfig{
Name: "cli",
Format: "raw",
Level: "trace",
})
instance := cli.NewApp()
instance.Name = "godev"
instance.Usage = "a development tool for golang"
instance.Description = "golang development tool with project bootstrap, live-reload, and auto-dependency retrieval powers"
instance.Version = Version
instance.Action = getDefaultAction(app.config)
instance.Commands = []cli.Command{
getInitCommand(app.config),
getTestCommand(app.config),
getVersionCommand(app.config, app.rawLogger),
getViewCommand(app.config, app.rawLogger),
}
instance.Flags = getDefaultFlags()
app.instance = instance
return app
}
// CLI is for handling the commands that GoDev takes in and
// sets the correct configuration flags
type CLI struct {
config *Config
instance *cli.App
logger *Logger
rawLogger *Logger
}
// Start triggers the CLI manager to parse the inputs and set
// the configuration flags correctly
func (app *CLI) Start(args []string, after func(*Config)) {
app.instance.After = func(c *cli.Context) error {
after(app.config)
return nil
}
if err := app.instance.Run(args); err != nil {
app.logger.Error(err)
app.logger.Warn("exiting with status code 1")
os.Exit(1)
}
}