forked from rancher/rio
/
inspect.go
72 lines (61 loc) · 1.37 KB
/
inspect.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
package inspect
import (
"errors"
"strings"
"github.com/rancher/rio/cli/pkg/clicontext"
"github.com/rancher/rio/cli/pkg/lookup"
"github.com/rancher/rio/cli/pkg/table"
clitypes "github.com/rancher/rio/cli/pkg/types"
"github.com/urfave/cli"
)
var (
InspectTypes = []string{
clitypes.ServiceType,
clitypes.AppType,
clitypes.ConfigType,
clitypes.NamespaceType,
clitypes.RouterType,
clitypes.ExternalServiceType,
clitypes.PodType,
clitypes.FeatureType,
clitypes.PublicDomainType,
clitypes.BuildType,
clitypes.SecretType,
}
)
type Inspect struct {
T_Type string `desc:"The specific type to inspect"`
}
func (i *Inspect) Customize(cmd *cli.Command) {
for _, f := range table.WriterFlags() {
if f.GetName() == "format" {
sf := f.(cli.StringFlag)
sf.Value = "yaml"
cmd.Flags = append(cmd.Flags, sf)
}
}
}
func (i *Inspect) Run(ctx *clicontext.CLIContext) error {
if len(ctx.CLI.Args()) == 0 {
return errors.New("at least one argument is required")
}
types := InspectTypes
if i.T_Type != "" {
types = []string{i.T_Type}
}
for _, arg := range ctx.CLI.Args() {
if strings.Contains(arg, ":") {
types = []string{clitypes.ServiceType}
}
r, err := lookup.Lookup(ctx, arg, types...)
if err != nil {
return err
}
t := table.NewWriter(nil, ctx)
t.Write(r.Object)
if err := t.Close(); err != nil {
return err
}
}
return nil
}