forked from spiffe/spire
-
Notifications
You must be signed in to change notification settings - Fork 4
/
cli.go
56 lines (51 loc) · 1.49 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
package cli
import (
"context"
stdlog "log"
"github.com/accuknox/spire/cmd/spire-agent/cli/api"
"github.com/accuknox/spire/cmd/spire-agent/cli/healthcheck"
"github.com/accuknox/spire/cmd/spire-agent/cli/run"
"github.com/accuknox/spire/cmd/spire-agent/cli/validate"
"github.com/accuknox/spire/pkg/common/log"
"github.com/accuknox/spire/pkg/common/version"
"github.com/mitchellh/cli"
)
type CLI struct {
LogOptions []log.Option
AllowUnknownConfig bool
}
func (cc *CLI) Run(ctx context.Context, args []string) int {
c := cli.NewCLI("spire-agent", version.Version())
c.Args = args
c.Commands = map[string]cli.CommandFactory{
"api fetch": func() (cli.Command, error) {
return api.NewFetchX509Command(), nil
},
"api fetch x509": func() (cli.Command, error) {
return api.NewFetchX509Command(), nil
},
"api fetch jwt": func() (cli.Command, error) {
return api.NewFetchJWTCommand(), nil
},
"api validate jwt": func() (cli.Command, error) {
return api.NewValidateJWTCommand(), nil
},
"api watch": func() (cli.Command, error) {
return &api.WatchCLI{}, nil
},
"run": func() (cli.Command, error) {
return run.NewRunCommand(ctx, cc.LogOptions, cc.AllowUnknownConfig), nil
},
"healthcheck": func() (cli.Command, error) {
return healthcheck.NewHealthCheckCommand(), nil
},
"validate": func() (cli.Command, error) {
return validate.NewValidateCommand(), nil
},
}
exitStatus, err := c.Run()
if err != nil {
stdlog.Println(err)
}
return exitStatus
}