Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions pkg/cmd/kafka/update/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"reflect"
"strconv"
"strings"

"github.com/AlecAivazis/survey/v2"
kafkamgmtclient "github.com/redhat-developer/app-services-sdk-go/kafkamgmt/apiv1/client"
Expand Down Expand Up @@ -291,10 +292,14 @@ func generateUpdateSummary(new reflect.Value, current reflect.Value) string {
fieldTag := field.Tag.Get("json")
fieldName := field.Name

oldVal := getElementValue(current.FieldByName(fieldName)).String()
newVal := getElementValue(new.FieldByName(fieldName)).String()
oldVal := getElementValue(current.FieldByName(fieldName))
newVal := getUpdateObjValue(new.FieldByName(fieldName))

summary += fmt.Sprintf("%v: %v %v %v\n", color.Bold(fieldTag), oldVal, icon.Emoji("\u27A1", "=>"), newVal)
fieldTagDisp := strings.Split(fieldTag, ",")[0]

if newVal != reflect.ValueOf(nil) {
summary += fmt.Sprintf("%v: %v %v %v\n", color.Bold(fieldTagDisp), oldVal, icon.Emoji("\u27A1", "=>"), newVal)
}
}

return summary
Expand All @@ -308,3 +313,12 @@ func getElementValue(v reflect.Value) reflect.Value {
}
return v
}

// get the true value from a reflect.Value for KafkaUpdateRequest struct
func getUpdateObjValue(v reflect.Value) reflect.Value {
if v.Kind() == reflect.Struct {
vstruct := v.FieldByName("value")
return vstruct.Elem()
}
return v
}
4 changes: 2 additions & 2 deletions pkg/localize/locales/en/cmd/acl.en.toml
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,10 @@ one = 'ACLs created to enable principal to consume messages from topics'
one = '"--group" or "--group-prefix" flag is allowed only when consumer ACLs are to be added'

[kafka.acl.grantPermissions.group.error.required]
one = '"--group" flag is required for consumer operation'
one = '"--group" or "--group-prefix" flag is required for consumer operation'

[kafka.acl.grantPermissions.topic.error.required]
one = '"--topic" flag is required for consumer and producer operations'
one = '"--topic" or "--topic-prefix" flag is required for consumer and producer operations'

[kafka.acl.grantPermissions.prefix.error.notAllowed]
one = 'can not use "--{{.Resource}}-prefix" and "--{{.Resource}}" flag together'
Expand Down