Skip to content

Commit

Permalink
Merge pull request #103574 from liggitt/restore-long-printing
Browse files Browse the repository at this point in the history
Restore ability to print long strings

Kubernetes-commit: 97d6e4a66af16a55646399c6880d38ae01379522
  • Loading branch information
k8s-publishing-bot committed Jul 8, 2021
2 parents f7c3433 + 792f804 commit 2cd779a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 27 deletions.
12 changes: 6 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ require (
github.com/stretchr/testify v1.7.0
golang.org/x/text v0.3.6
gopkg.in/yaml.v2 v2.4.0
k8s.io/api v0.0.0-20210708014407-1e1dad4bd9d1
k8s.io/apimachinery v0.0.0-20210708014216-0dafcb48b31e
k8s.io/client-go v0.0.0-20210708094636-69e00b04ba4c
k8s.io/api v0.0.0-20210708214500-0ff29d3f16e4
k8s.io/apimachinery v0.0.0-20210708214246-ff522ab81c74
k8s.io/client-go v0.0.0-20210708214810-7a90b08589bb
k8s.io/kube-openapi v0.0.0-20210421082810-95288971da7e
sigs.k8s.io/kustomize/api v0.8.11
sigs.k8s.io/kustomize/kyaml v0.11.0
sigs.k8s.io/yaml v1.2.0
)

replace (
k8s.io/api => k8s.io/api v0.0.0-20210708014407-1e1dad4bd9d1
k8s.io/apimachinery => k8s.io/apimachinery v0.0.0-20210708014216-0dafcb48b31e
k8s.io/client-go => k8s.io/client-go v0.0.0-20210708094636-69e00b04ba4c
k8s.io/api => k8s.io/api v0.0.0-20210708214500-0ff29d3f16e4
k8s.io/apimachinery => k8s.io/apimachinery v0.0.0-20210708214246-ff522ab81c74
k8s.io/client-go => k8s.io/client-go v0.0.0-20210708214810-7a90b08589bb
)
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -599,12 +599,12 @@ honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWh
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
k8s.io/api v0.0.0-20210708014407-1e1dad4bd9d1 h1:BsVbhrF9ZXWlpo/84y3WdGGw+SYu61RlNKOMqGKDIQE=
k8s.io/api v0.0.0-20210708014407-1e1dad4bd9d1/go.mod h1:UGtjmHCgj1IMXqa0rRAXNNszZBo1IKpAhbvSre33vSU=
k8s.io/apimachinery v0.0.0-20210708014216-0dafcb48b31e h1:EZ+ZrcPtnkR8vVo7bBSwoMD9a0HaC29O6lJhcZgwsJQ=
k8s.io/apimachinery v0.0.0-20210708014216-0dafcb48b31e/go.mod h1:O3oNtNadZdeOMxHFVxOreoznohCpy0z6mocxbZr7oJ0=
k8s.io/client-go v0.0.0-20210708094636-69e00b04ba4c h1:bm2mq36WyGKROFmZlbM7pjKGB+lMtClCABatAi2olrg=
k8s.io/client-go v0.0.0-20210708094636-69e00b04ba4c/go.mod h1:gdC8LfT2kw5hm9VcRUqlVkMMkbfYIxDWvPITF7hl7K8=
k8s.io/api v0.0.0-20210708214500-0ff29d3f16e4 h1:SONTS5tRMTV7iWmw9T6C7vsEFrQy4bygwu/PaUJP2Lo=
k8s.io/api v0.0.0-20210708214500-0ff29d3f16e4/go.mod h1:72i8FbvEsYM9+Hy9ZRCr4WADf5G8kTsusBNrcSkt2aY=
k8s.io/apimachinery v0.0.0-20210708214246-ff522ab81c74 h1:Daxg4VCqUpkKuMJjia7XcVVDHnPjH6IeKb7jcZDcQUM=
k8s.io/apimachinery v0.0.0-20210708214246-ff522ab81c74/go.mod h1:O3oNtNadZdeOMxHFVxOreoznohCpy0z6mocxbZr7oJ0=
k8s.io/client-go v0.0.0-20210708214810-7a90b08589bb h1:Hx8ZvH95DUXm9tFnwAAvyNmZGMSn+jiMZ19AtnQvEPA=
k8s.io/client-go v0.0.0-20210708214810-7a90b08589bb/go.mod h1:sf6aX4lO8AyErF5l4A2Aa//yf44Xb5ghYUCNLRBLOKk=
k8s.io/gengo v0.0.0-20200413195148-3a45101e95ac/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0=
k8s.io/klog/v2 v2.0.0/go.mod h1:PBfzABfn139FHAV07az/IF9Wp1bkk3vpT2XSJ76fSDE=
k8s.io/klog/v2 v2.9.0 h1:D7HV+n1V57XeZ0m6tdRkfknthUaM06VFbWldOFh8kzM=
Expand Down
17 changes: 5 additions & 12 deletions 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 @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions pkg/printers/tableprinter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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...
`,
},
}
Expand Down

0 comments on commit 2cd779a

Please sign in to comment.