Skip to content

Commit

Permalink
chore(service describe): Sort maps by key when printed
Browse files Browse the repository at this point in the history
  • Loading branch information
rhuss committed Aug 6, 2019
1 parent 4cc8a34 commit 39f77a4
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions pkg/kn/commands/service/service_describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,16 +336,23 @@ func shortenDigest(digest string) string {
}

// Write a map either compact in a single line (possibly truncated) or, if printDetails is set,
// over multiple line, one line per key-value pair
// over multiple line, one line per key-value pair. The output is sorted by keys.
func writeMapDesc(dw printers.PrefixWriter, indent int, m map[string]string, label string, labelPrefix string) {
if len(m) == 0 {
return
}

if printDetails {
l := labelPrefix + label
for key, value := range m {
dw.WriteColsLn(indent, l, key+"="+value)

var keys []string
for k := range m {
keys = append(keys, k)
}
sort.Strings(keys)

for _, key := range keys {
dw.WriteColsLn(indent, l, key+"="+m[key])
l = labelPrefix
}
return
Expand Down

0 comments on commit 39f77a4

Please sign in to comment.