in pkg/printers/tableprinter.go [172:233]
func printTable(table *metav1.Table, output io.Writer, options PrintOptions) error {
if !options.NoHeaders {
// avoid printing headers if we have no rows to display
if len(table.Rows) == 0 {
return nil
}
first := true
for _, column := range table.ColumnDefinitions {
if !options.Wide && column.Priority != 0 {
continue
}
if first {
first = false
} else {
fmt.Fprint(output, "\t")
}
fmt.Fprint(output, strings.ToUpper(column.Name))
}
fmt.Fprintln(output)
}
for _, row := range table.Rows {
first := true
for i, cell := range row.Cells {
if i >= len(table.ColumnDefinitions) {
// https://issue.k8s.io/66379
// don't panic in case of bad output from the server, with more cells than column definitions
break
}
column := table.ColumnDefinitions[i]
if !options.Wide && column.Priority != 0 {
continue
}
if first {
first = false
} else {
fmt.Fprint(output, "\t")
}
if cell != nil {
switch val := cell.(type) {
case string:
print := val
truncated := false
// truncate at newlines
newline := strings.Index(print, "\n")
if newline >= 0 {
truncated = true
print = print[:newline]
}
fmt.Fprint(output, print)
if truncated {
fmt.Fprint(output, "...")
}
default:
fmt.Fprint(output, val)
}
}
}
fmt.Fprintln(output)
}
return nil
}