-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
49 lines (40 loc) · 1.1 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
package main
import (
"os"
"path"
"github.com/rancher/wrangler/pkg/signals"
"github.com/urfave/cli/v2"
"go.uber.org/zap"
"github.com/ekristen/go-project-template/pkg/common"
_ "github.com/ekristen/go-project-template/pkg/commands/example"
_ "github.com/ekristen/go-project-template/pkg/commands/server"
)
func main() {
defer func() {
if r := recover(); r != nil {
// log panics using zap and force exit
zap.L().Error("panic recovered", zap.Any("panic", r))
os.Exit(1)
}
}()
app := cli.NewApp()
app.Name = path.Base(os.Args[0])
app.Usage = common.AppVersion.Name
app.Version = common.AppVersion.Summary
app.Authors = []*cli.Author{
{
Name: "Erik Kristensen",
Email: "[email protected]",
},
}
app.Before = common.Before
app.Flags = common.Flags()
app.Commands = common.GetCommands()
app.CommandNotFound = func(context *cli.Context, command string) {
zap.L().Fatal("command not found.", zap.String("command", command))
}
ctx := signals.SetupSignalContext()
if err := app.RunContext(ctx, os.Args); err != nil {
zap.L().Fatal("fatal error", zap.Error(err))
}
}