diff --git a/internal/human/marshal.go b/internal/human/marshal.go index b50419f844..f0bb8c0702 100644 --- a/internal/human/marshal.go +++ b/internal/human/marshal.go @@ -98,7 +98,7 @@ func marshalStruct(value reflect.Value, opt *MarshalOpt) (string, error) { sectionsStrs := []string(nil) sectionFieldNames := map[string]bool{} for _, section := range opt.Sections { - sectionStr, err := marshalSection(section, value, subOpts) + sectionStr, err := marshalSection(section, value, opt.subOption(section.FieldName)) if err != nil { return "", err } diff --git a/internal/human/specs.go b/internal/human/specs.go index 5b25eced26..f8dd214571 100644 --- a/internal/human/specs.go +++ b/internal/human/specs.go @@ -8,9 +8,10 @@ import ( // MarshalOpt is hydrated by core.View type MarshalOpt struct { - Title string - Fields []*MarshalFieldOpt - Sections []*MarshalSection + Title string + Fields []*MarshalFieldOpt + Sections []*MarshalSection + SubOptions map[string]*MarshalOpt // Is set to true if we are marshaling a table cell TableCell bool @@ -19,6 +20,15 @@ type MarshalOpt struct { DisableShrinking bool } +func (m *MarshalOpt) subOption(section string) *MarshalOpt { + subOpt, exists := m.SubOptions[section] + if exists { + return subOpt + } + + return &MarshalOpt{} +} + type MarshalFieldOpt struct { FieldName string Label string diff --git a/internal/namespaces/redis/v1/custom.go b/internal/namespaces/redis/v1/custom.go index f045336dc8..d45c404c82 100644 --- a/internal/namespaces/redis/v1/custom.go +++ b/internal/namespaces/redis/v1/custom.go @@ -10,7 +10,6 @@ func GetCommands() *core.Commands { cmds := GetGeneratedCommands() human.RegisterMarshalerFunc(redis.Cluster{}, redisClusterGetMarshalerFunc) - human.RegisterMarshalerFunc(redis.Cluster{}.Endpoints, redisEndpointsClusterGetMarshalerFunc) cmds.Merge(core.NewCommands(clusterWaitCommand())) cmds.MustFind("redis", "cluster", "create").Override(clusterCreateBuilder) diff --git a/internal/namespaces/redis/v1/custom_cluster.go b/internal/namespaces/redis/v1/custom_cluster.go index 5e0cbabedd..4b427e6897 100644 --- a/internal/namespaces/redis/v1/custom_cluster.go +++ b/internal/namespaces/redis/v1/custom_cluster.go @@ -3,7 +3,6 @@ package redis import ( "context" "errors" - "log" "net/http" "reflect" "strings" @@ -170,34 +169,9 @@ func redisSettingAddBuilder(c *core.Command) *core.Command { return c } -func redisEndpointsClusterGetMarshalerFunc(i interface{}, opt *human.MarshalOpt) (string, error) { - type tmp []*redis.Endpoint - redisEndpointsClusterResponse := tmp(i.([]*redis.Endpoint)) - opt.Fields = []*human.MarshalFieldOpt{ - { - FieldName: "ID", - Label: "ID", - }, - { - FieldName: "Port", - Label: "Port", - }, - { - FieldName: "IPs", - Label: "IPs", - }, - } - str, err := human.Marshal(redisEndpointsClusterResponse, opt) - if err != nil { - return "", err - } - return str, nil -} - func redisClusterGetMarshalerFunc(i interface{}, opt *human.MarshalOpt) (string, error) { type tmp redis.Cluster redisClusterResponse := tmp(i.(redis.Cluster)) - log.Println("redis ", i.(redis.Cluster).Endpoints[0]) opt.Sections = []*human.MarshalSection{ { FieldName: "Endpoints", @@ -208,6 +182,24 @@ func redisClusterGetMarshalerFunc(i interface{}, opt *human.MarshalOpt) (string, Title: "ACLRules", }, } + opt.SubOptions = map[string]*human.MarshalOpt{ + "Endpoints": { + Fields: []*human.MarshalFieldOpt{ + { + FieldName: "ID", + Label: "ID", + }, + { + FieldName: "Port", + Label: "Port", + }, + { + FieldName: "IPs", + Label: "IPs", + }, + }, + }, + } str, err := human.Marshal(redisClusterResponse, opt) if err != nil { return "", err