Skip to content
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

Restore the ability to print long strings, but still cut newlines #103582

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 0 additions & 8 deletions staging/src/k8s.io/cli-runtime/pkg/printers/tableprinter.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ import (
"k8s.io/apimachinery/pkg/watch"
)

const maxStringLength = 100

var _ ResourcePrinter = &HumanReadablePrinter{}

type printHandler struct {
Expand Down Expand Up @@ -214,12 +212,6 @@ func printTable(table *metav1.Table, output io.Writer, options PrintOptions) err
case string:
print := val
more := 0
// cut to maxStringLength
if len(val) > maxStringLength {
more = len(print) - maxStringLength
print = print[:maxStringLength]
}
// and also check for newlines
newline := strings.Index(print, "\n")
if newline >= 0 {
more = more + len(print) - newline
Expand Down
28 changes: 0 additions & 28 deletions staging/src/k8s.io/cli-runtime/pkg/printers/tableprinter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -741,34 +741,6 @@ func TestStringPrinting(t *testing.T) {
},
expected: `NAME AGE DESCRIPTION
test1 20h This is first line + 56 more...
`,
},
// lengthy string
{
columns: []metav1.TableColumnDefinition{
{Name: "Name", Type: "string"},
{Name: "Age", Type: "string"},
{Name: "Description", Type: "string"},
},
rows: []metav1.TableRow{
{Cells: []interface{}{"test1", "20h", "This is first line which is long and goes for on and on and on an on and on and on and on and on and on and on and on and on and on and on"}},
},
expected: `NAME AGE DESCRIPTION
test1 20h This is first line which is long and goes for on and on and on an on and on and on and on and on and + 38 more...
`,
},
// lengthy string + newline
{
columns: []metav1.TableColumnDefinition{
{Name: "Name", Type: "string"},
{Name: "Age", Type: "string"},
{Name: "Description", Type: "string"},
},
rows: []metav1.TableRow{
{Cells: []interface{}{"test1", "20h", "This is first\n line which is long and goes for on and on and on an on and on and on and on and on and on and on and on and on and on and on"}},
},
expected: `NAME AGE DESCRIPTION
test1 20h This is first + 126 more...
`,
},
}
Expand Down