Skip to content

Commit

Permalink
output: Return empty []Field if len(outputSlice) == 0.
Browse files Browse the repository at this point in the history
  • Loading branch information
paladin-devops committed Mar 25, 2024
1 parent 5b88eff commit 3131ebd
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 9 deletions.
5 changes: 0 additions & 5 deletions internal/commands/waypoint/add-on/add_on_definition_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,5 @@ func addOnDefinitionsList(opts *AddOnDefinitionOpts) error {
addOnDefinitions = append(addOnDefinitions, listResp.GetPayload().AddOnDefinitions...)
}

// This is done so that we don't panic on Output.Show if there are no add-on definitions
if len(addOnDefinitions) == 0 {
return nil
}

return opts.Output.Show(addOnDefinitions, format.Pretty)
}
2 changes: 0 additions & 2 deletions internal/commands/waypoint/template/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,5 @@ func listTemplates(opts *TemplateOpts) error {
templates = append(templates, resp.GetPayload().ApplicationTemplates...)
}

// TODO: Fix panic if len(addOnDefinitions) == 0

return opts.Output.Show(templates, format.Pretty)
}
7 changes: 5 additions & 2 deletions internal/pkg/format/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,12 @@ func inferFields[T any](payload T, columns []string) []Field {
rv = rv.Elem()
}

var ret []Field

if rv.Kind() == reflect.Slice {
if rv.Len() == 0 {
return ret
}
rv = rv.Index(0)

for rv.Kind() == reflect.Pointer {
Expand All @@ -98,8 +103,6 @@ func inferFields[T any](payload T, columns []string) []Field {

st := rv.Type()

var ret []Field

all := len(toField) == 0

if !all {
Expand Down

0 comments on commit 3131ebd

Please sign in to comment.