Skip to content

Commit c177897

Browse files
authored
Improve list result output (#37344)
1 parent 3607089 commit c177897

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

internal/command/views/hook_ui.go

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -514,17 +514,28 @@ func (h *UiHook) PreListQuery(id terraform.HookResourceIdentity, input_config ct
514514
func (h *UiHook) PostListQuery(id terraform.HookResourceIdentity, results plans.QueryResults) (terraform.HookAction, error) {
515515
addr := id.Addr
516516
data := results.Value.GetAttr("data")
517+
518+
identities := make([]string, 0, data.LengthInt())
519+
displayNames := make([]string, 0, data.LengthInt())
520+
maxIdentityLen := 0
517521
for it := data.ElementIterator(); it.Next(); {
518522
_, value := it.Element()
523+
identity := tfdiags.ObjectToString(value.GetAttr("identity"))
524+
if len(identity) > maxIdentityLen {
525+
maxIdentityLen = len(identity)
526+
}
527+
identities = append(identities, identity)
519528

520-
h.println(fmt.Sprintf(
521-
"%s\t%s\t%s",
522-
addr.String(),
523-
// TODO maybe deduplicate common identity attributes?
524-
tfdiags.ObjectToString(value.GetAttr("identity")),
525-
value.GetAttr("display_name").AsString(),
526-
))
529+
displayNames = append(displayNames, value.GetAttr("display_name").AsString())
527530
}
531+
532+
result := strings.Builder{}
533+
for i, identity := range identities {
534+
result.WriteString(fmt.Sprintf("%s %-*s %s\n", addr.String(), maxIdentityLen, identity, displayNames[i]))
535+
}
536+
537+
h.println(result.String())
538+
528539
return terraform.HookActionContinue, nil
529540
}
530541

0 commit comments

Comments
 (0)