This repository has been archived by the owner on Feb 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
74 lines (62 loc) · 1.85 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
package main
import (
"fmt"
"github.com/alecthomas/kong"
)
var (
Version = "undefined"
BuildDate = "now"
)
type HelpCmd struct {
Command []string `arg optional help:"Show help on command"`
}
// Run shows help.
func (c *HelpCmd) Run(realCtx *kong.Context) error {
ctx, err := kong.Trace(realCtx.Kong, c.Command)
if err != nil {
return err
}
if ctx.Error != nil {
return ctx.Error
}
err = ctx.PrintUsage(false)
if err != nil {
return err
}
fmt.Fprintln(realCtx.Stdout)
return nil
}
type VersionCmd struct{}
func (v VersionCmd) Run(ctx *kong.Context) error {
fmt.Println(Version)
return nil
}
type VersionFlag string
func (v VersionFlag) Decode(ctx *kong.DecodeContext) error { return nil }
func (v VersionFlag) IsBool() bool { return true }
func (v VersionFlag) BeforeApply(app *kong.Kong, vars kong.Vars) error {
fmt.Println(Version)
app.Exit(0)
return nil
}
type CLI struct {
Version VersionCmd `cmd help:"Print version information and quit"`
VersionFlag VersionFlag `name:"version" help:"Print version information and quit"`
Help HelpCmd `cmd help:"Show this help"`
CheckAmi CheckAmiCmd `cmd name:"check-ami" help:"Check whether there's a newer AMI than the one referenced in th current LaunchTemplate"`
ListUpgradable ListUpgradableCmd `cmd name:"list-upgradable" help:"List nodes which are running off an outdated LaunchTemplate version"`
Upgrade UpgradeCmd `cmd help:"Upgrade nodes which are running off an outdated LaunchTemplate version"`
}
func main() {
cli := CLI{}
ctx := kong.Parse(&cli,
kong.Name("boatswain"),
kong.Description("Boatswain helps automate EKS node maintenance and upgrades"),
kong.UsageOnError(),
kong.ConfigureHelp(kong.HelpOptions{
Compact: true,
Summary: true,
}))
err := ctx.Run()
ctx.FatalIfErrorf(err)
}