From 7dc8770bf2e34b8afda25814681778b46ad22293 Mon Sep 17 00:00:00 2001 From: Tim Gross Date: Wed, 2 Oct 2024 10:00:07 -0400 Subject: [PATCH] refactor: clean up slice initialization in node status We initialize this slice with a zeroed array and then append to it, which means we then have to clean out the empty strings later. Initialize to the correct capacity up front so there are no empty values. Ref: https://github.com/hashicorp/nomad/pull/24104 --- command/node_status.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/command/node_status.go b/command/node_status.go index 37b59babc71..f7f7b587802 100644 --- a/command/node_status.go +++ b/command/node_status.go @@ -793,18 +793,16 @@ func formatEventDetails(details map[string]string) string { } func (c *NodeStatusCommand) formatAttributes(node *api.Node) { - // Print the attributes - keys := make([]string, len(node.Attributes)) + keys := make([]string, 0, len(node.Attributes)) for k := range node.Attributes { keys = append(keys, k) } + sort.Strings(keys) var attributes []string for _, k := range keys { - if k != "" { - attributes = append(attributes, fmt.Sprintf("%s|%s", k, node.Attributes[k])) - } + attributes = append(attributes, fmt.Sprintf("%s|%s", k, node.Attributes[k])) } c.Ui.Output(c.Colorize().Color("\n[bold]Attributes[reset]")) c.Ui.Output(formatKV(attributes))