func topList(jsondata map[string]interface{}) { const searchKey = "models" //TODO outputresult := jvmap.JsonValueMap(jsondata, searchKey) for k, _ := range outputresult[0][0][searchKey].(map[string]interface{}) { if jvmap.JsonValueMap(jsondata, "kind", k) != nil { fmt.Printf("%v ", k) } } }
func getRef(jsondata map[string]interface{}, searchKey string, depth int) map[string]interface{} { const rootKey = "properties" outputresult := jvmap.JsonValueMap(jsondata, rootKey, searchKey) manifestedParameters := outputresult[0][0][rootKey].(map[string]interface{}) delete(manifestedParameters, "status") //TODO: smart way? manifestedParameters = ManifestScanner(jsondata, manifestedParameters, depth) return manifestedParameters }
func RunSnippet(cmd *cobra.Command, searchKey string) error { filelocation := cmdutil.GetFlagString(cmd, "filename") insecure := cmdutil.GetFlagBool(cmd, "insecure") jsondataRaw, err := ReadConfigDataFromLocation(filelocation, insecure) if err != nil { return fmt.Errorf("%s", err) } jsondata := map[string]interface{}{} err = json.Unmarshal(jsondataRaw, &jsondata) if err != nil { return fmt.Errorf("%s", err) } descripitonresult := jvmap.JsonValueMap(jsondata, searchKey) var foundSnippetList []map[string]interface{} for k, _ := range descripitonresult { foundSnippetList = append(foundSnippetList, logic.JsonValueParentChain(jsondata, descripitonresult[k][0], searchKey)) } if foundSnippetList == nil { return fmt.Errorf("Not match parameter %s in %s", searchKey, filelocation) } else if n := len(foundSnippetList); n > 1 { fmt.Printf("\"%s\" found at %d locations\n", searchKey, n) for k, _ := range descripitonresult { fmt.Printf("\n") if err = refPart(foundSnippetList[k]); err != nil { return fmt.Errorf("%s", err) } } } else { if err = refPart(descripitonresult[0][0]); err != nil { return fmt.Errorf("%s", err) } } return nil }