From 92541f46e6b38264927b17d0becb07fa11902b17 Mon Sep 17 00:00:00 2001 From: Jordan Liggitt Date: Thu, 8 Jul 2021 01:53:01 -0400 Subject: [PATCH] Restore ability to print long strings --- .../cli-runtime/pkg/printers/tableprinter.go | 17 +++++------------ .../pkg/printers/tableprinter_test.go | 6 +++--- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/staging/src/k8s.io/cli-runtime/pkg/printers/tableprinter.go b/staging/src/k8s.io/cli-runtime/pkg/printers/tableprinter.go index b8211e529c5..c32e5fdf6a5 100644 --- a/staging/src/k8s.io/cli-runtime/pkg/printers/tableprinter.go +++ b/staging/src/k8s.io/cli-runtime/pkg/printers/tableprinter.go @@ -32,8 +32,6 @@ import ( "k8s.io/apimachinery/pkg/watch" ) -const maxStringLength = 100 - var _ ResourcePrinter = &HumanReadablePrinter{} type printHandler struct { @@ -213,21 +211,16 @@ func printTable(table *metav1.Table, output io.Writer, options PrintOptions) err switch val := cell.(type) { 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 + truncated := false + // truncate at newlines newline := strings.Index(print, "\n") if newline >= 0 { - more = more + len(print) - newline + truncated = true print = print[:newline] } fmt.Fprint(output, print) - if more > 0 { - fmt.Fprintf(output, " + %d more...", more) + if truncated { + fmt.Fprint(output, "...") } default: fmt.Fprint(output, val) diff --git a/staging/src/k8s.io/cli-runtime/pkg/printers/tableprinter_test.go b/staging/src/k8s.io/cli-runtime/pkg/printers/tableprinter_test.go index 770067cf50d..b2caaa12838 100644 --- a/staging/src/k8s.io/cli-runtime/pkg/printers/tableprinter_test.go +++ b/staging/src/k8s.io/cli-runtime/pkg/printers/tableprinter_test.go @@ -740,7 +740,7 @@ func TestStringPrinting(t *testing.T) { {Cells: []interface{}{"test1", "20h", "This is first line\nThis is second line\nThis is third line\nand another one\n"}}, }, expected: `NAME AGE DESCRIPTION -test1 20h This is first line + 56 more... +test1 20h This is first line... `, }, // lengthy string @@ -754,7 +754,7 @@ test1 20h This is first line + 56 more... {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... +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 `, }, // lengthy string + newline @@ -768,7 +768,7 @@ test1 20h This is first line which is long and goes for on and on and on an {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... +test1 20h This is first... `, }, }