Exemple #1
0
func (gohanClientCLI *GohanClientCLI) createResourcesTable(buffer *bytes.Buffer, resources []interface{}) {
	table := tablewriter.NewWriter(buffer)
	allKeysResource := map[string]interface{}{}
	for _, resource := range resources {
		for key := range resource.(map[string]interface{}) {
			allKeysResource[key] = ""
		}
	}
	keys := util.GetSortedKeys(allKeysResource)
	if len(keys) == 0 {
		return
	}
	table.SetHeader(keys)
	for _, resource := range resources {
		resourceSlice := []string{}
		for _, key := range keys {
			v := ""
			if val, ok := resource.(map[string]interface{})[key]; ok {
				v = fmt.Sprint(val)
			}
			resourceSlice = append(resourceSlice, v)
		}
		table.Append(resourceSlice)
	}
	table.Render()
}
Exemple #2
0
func (gohanClientCLI *GohanClientCLI) createSingleResourceTable(buffer *bytes.Buffer, resource map[string]interface{}) {
	table := tablewriter.NewWriter(buffer)
	table.SetHeader([]string{"Property", "Value"})
	keys := util.GetSortedKeys(resource)
	for _, key := range keys {
		table.Append([]string{key, fmt.Sprint(resource[key])})
	}
	table.Render()
}