forked from kubernetes-sigs/reference-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgvkeysmap.go
43 lines (40 loc) · 991 Bytes
/
gvkeysmap.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
package cli
import (
"fmt"
"sort"
"github.com/kubernetes-sigs/reference-docs/gen-resourcesdocs/pkg/kubernetes"
"github.com/spf13/cobra"
)
// GVKeysMap defines the `gvkeysmap` subcommand
func GVKeysMap() *cobra.Command {
cmd := &cobra.Command{
Use: "gvkeysmap",
Short: "show the map between group/version and definition keys",
Long: "show the map between group/version and definition keys",
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
}
gvs := make([]string, len(spec.GVToKey))
i := 0
for gv := range spec.GVToKey {
gvs[i] = gv
i++
}
sort.Strings(gvs)
for _, gv := range gvs {
keys := spec.GVToKey[gv]
fmt.Printf("%s\n", gv)
for _, key := range keys {
fmt.Printf("\t%s\n", key)
}
}
return nil
},
}
return cmd
}