-
Notifications
You must be signed in to change notification settings - Fork 0
/
handler.go
45 lines (37 loc) · 1.02 KB
/
handler.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
package handler
import (
"os"
"os/user"
"github.com/alecthomas/kong"
"github.com/tb0hdan/aws-k8s/pkg/commands"
"github.com/tb0hdan/aws-k8s/pkg/utils"
)
type AWSCommand struct {
Commands []kong.Option
}
func (a *AWSCommand) ClearEnvironment() {
// clear environment first
utils.UnsetEnvList("AWS_ACCESS_KEY_ID", "AWS_SECRET_ACCESS_KEY", "AWS_SESSION_TOKEN")
}
func (a *AWSCommand) AddCommand(name, help, group string, cmd interface{}, tags ...string) {
a.Commands = append(a.Commands, kong.DynamicCommand(name, help, group, cmd, tags...))
}
func (a *AWSCommand) Parse(cliStruct interface{}) *kong.Context {
// Show help by default
if len(os.Args) == 1 {
os.Args = append(os.Args, "-h")
}
return kong.Parse(cliStruct, a.Commands...)
}
func (a *AWSCommand) Run(cli *kong.Context, debug bool) {
// get current user
currentUser, err := user.Current()
if err != nil {
panic(err)
}
//
cli.FatalIfErrorf(cli.Run(&commands.CLIContext{Debug: debug, User: currentUser}))
}
func New() *AWSCommand {
return &AWSCommand{}
}