-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
65 lines (56 loc) · 1.58 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
package main
import (
"os"
log "github.com/sirupsen/logrus"
"github.com/fatih/color"
"github.com/tcnksm/go-latest"
"github.com/urfave/cli"
"github.com/vapor-ware/sctl/commands"
"github.com/vapor-ware/sctl/version"
)
func main() {
app := cli.NewApp()
app.Name = "sctl"
app.Usage = "Manage secrets encrypted by KMS"
app.Version = version.Version
app.Flags = []cli.Flag{
cli.BoolFlag{
Name: "debug",
EnvVar: "SCTL_DEBUG",
Usage: "Enable debug logging statements",
},
}
app.Before = func(c *cli.Context) error {
// Allow debugging of the config loading process
if c.Bool("debug") {
log.SetLevel(log.DebugLevel)
}
return nil
}
// TODO (etd): This functionality could be moved to utils or elsewhere, but since the
// current version is defined here, we need to be within the app scope to get to it.
// This could be alleviated by encoding the version elsewhere or using build-time
// args to pass in version information.
app.After = func(context *cli.Context) error {
tag := &latest.GithubTag{
Owner: "vapor-ware",
Repository: "sctl",
}
res, err := latest.Check(tag, app.Version)
if err != nil {
// A failure to check should not result in a failure to use the tool. Just
// log the issue and continue on.
log.Debugf("failed to check for latest version: %v", err)
return nil
}
if res.Outdated {
color.Yellow("\nA new version of sctl is available: current=%s, latest=%s", app.Version, res.Current)
}
return nil
}
app.Commands = commands.BuildContextualMenu()
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}