Skip to content

feat(cli): add json output to coder speedtest #13475

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
WIP
  • Loading branch information
ethanndickson committed Jun 5, 2024
commit a93efdb1371b7ed95a166b2d757a4ebdce00b24e
2 changes: 1 addition & 1 deletion cli/cliui/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func (f *tableFormat) AttachOptions(opts *serpent.OptionSet) {

// Format implements OutputFormat.
func (f *tableFormat) Format(_ context.Context, data any) (string, error) {
return doDisplayTable(data, f.sort, f.columns, nil)
return renderTable(data, f.sort, f.columns, nil)
}

type jsonFormat struct{}
Expand Down
12 changes: 6 additions & 6 deletions cli/cliui/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,18 @@ func DisplayTable(out any, sort string, filterColumns []string) (string, error)
if v.Kind() != reflect.Slice {
return "", xerrors.Errorf("DisplayTable called with a non-slice type")
}
var fst reflect.Type
var tableType reflect.Type
if v.Type().Elem().Kind() == reflect.Interface {
if v.Len() == 0 {
return "", xerrors.Errorf("DisplayTable called with empty interface slice")
}
fst = reflect.Indirect(reflect.ValueOf(v.Index(0).Interface())).Type()
tableType = reflect.Indirect(reflect.ValueOf(v.Index(0).Interface())).Type()
} else {
fst = v.Type().Elem()
tableType = v.Type().Elem()
}

// Get the list of table column headers.
headersRaw, defaultSort, err := typeToTableHeaders(fst, true)
headersRaw, defaultSort, err := typeToTableHeaders(tableType, true)
if err != nil {
return "", xerrors.Errorf("get table headers recursively for type %q: %w", v.Type().Elem().String(), err)
}
Expand Down Expand Up @@ -142,10 +142,10 @@ func DisplayTable(out any, sort string, filterColumns []string) (string, error)
return "", xerrors.Errorf("specified sort column %q not found in table headers, available columns are %q", sort, strings.Join(headersRaw, `", "`))
}
}
return doDisplayTable(out, sort, headersRaw, filterColumns)
return renderTable(out, sort, headersRaw, filterColumns)
}

func doDisplayTable(out any, sort string, headersRaw []string, filterColumns []string) (string, error) {
func renderTable(out any, sort string, headersRaw []string, filterColumns []string) (string, error) {
v := reflect.Indirect(reflect.ValueOf(out))

headers := make(table.Row, len(headersRaw))
Expand Down
1 change: 1 addition & 0 deletions cli/speedtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type speedtestTableItem struct {
Throughput string `table:"Throughput"`
}

// Attaches a CLI arg with table output
type speedtestTableFormatter struct {
tableFormatter cliui.OutputFormat
}
Expand Down