forked from kubernetes-sigs/reference-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresourceslist.go
45 lines (41 loc) · 1016 Bytes
/
resourceslist.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 cli
import (
"fmt"
"sort"
"github.com/kubernetes-sigs/reference-docs/gen-resourcesdocs/pkg/kubernetes"
"github.com/spf13/cobra"
)
// ResourceslistCmd defines the `resourceslist` subcommand
func ResourceslistCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "resourceslist",
Short: "list k8s resources",
Long: "list Kubernetes resources in the specification",
SilenceErrors: true,
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
file := cmd.Flag(fileOption).Value.String()
spec, err := kubernetes.NewSpec(file)
if err != nil {
return err
}
resources := spec.Resources
i := 0
keys := make([]string, len(*resources))
for k := range *resources {
keys[i] = k.String()
i++
}
sort.Strings(keys)
for _, k := range keys {
rs := (*resources)[kubernetes.APIKind(k)]
fmt.Println(k)
for _, r := range rs {
fmt.Println("\t" + r.GetGV())
}
}
return nil
},
}
return cmd
}