MCPcopy Index your code
hub / github.com/coder/coder / TableFormat

Function TableFormat

cli/cliui/output.go:112–134  ·  view source on GitHub ↗

TableFormat creates a table formatter for the given output type. The output type should be specified as an empty slice of the desired type. E.g.: TableFormat([]MyType{}, []string{"foo", "bar"}) defaultColumns is optional and specifies the default columns to display. If not specified, all columns a

(out any, defaultColumns []string)

Source from the content-addressed store, hash-verified

110// If the data is empty, an empty string is returned. Callers should check for
111// this and provide an appropriate message to the user.
112func TableFormat(out any, defaultColumns []string) OutputFormat {
113 v := reflect.Indirect(reflect.ValueOf(out))
114 if v.Kind() != reflect.Slice {
115 panic("DisplayTable called with a non-slice type")
116 }
117
118 // Get the list of table column headers.
119 headers, defaultSort, err := typeToTableHeaders(v.Type().Elem(), true)
120 if err != nil {
121 panic("parse table headers: " + err.Error())
122 }
123
124 tf := &tableFormat{
125 defaultColumns: headers,
126 allColumns: headers,
127 sort: defaultSort,
128 }
129 if len(defaultColumns) > 0 {
130 tf.defaultColumns = defaultColumns
131 }
132
133 return tf
134}
135
136// ID implements OutputFormat.
137func (*tableFormat) ID() string {

Callers 15

templatePresetsListMethod · 0.92
showOrganizationRolesMethod · 0.92
templateListMethod · 0.92
whoamiMethod · 0.92
workspaceACLToTableFunction · 0.92
scheduleShowMethod · 0.92
taskStatusMethod · 0.92
provisionerJobsListMethod · 0.92
taskLogsMethod · 0.92

Calls 3

typeToTableHeadersFunction · 0.85
TypeMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected