// limitFields returns only the fields the user specified in the `fields` flag. If // the flag wasn't provided, all fields are returned. func (ctx *Context) limitFields(resource *Resource) { if ctx.CLIContext.IsSet("fields") { fields := strings.Split(strings.ToLower(ctx.CLIContext.String("fields")), ",") newKeys := []string{} for _, key := range resource.Keys { if util.Contains(fields, strings.Join(strings.Split(strings.ToLower(key), " "), "-")) { newKeys = append(newKeys, key) } } resource.Keys = newKeys } }
// FlattenMap is used to flatten out a `map[string]map[string]*` func (resource *Resource) FlattenMap(key string) { keys := resource.Keys res := resource.Result.(map[string]interface{}) if m, ok := res[key]; ok && util.Contains(keys, key) { switch m.(type) { case map[string]interface{}: for k, v := range m.(map[string]interface{}) { res[k] = v keys = append(keys, k) } case map[string]string: for k, v := range m.(map[string]string) { res[k] = v keys = append(keys, k) } } } delete(res, key) resource.Keys = util.RemoveFromList(keys, key) }