Merge pull request #126533 from ah8ad3/kubectl-explain-wrap
Realign line breaks in kubectl explain wrap method Kubernetes-commit: 602c70b65d49e0687026064edb8601087da00bd2
This commit is contained in:
commit
e91a2f1400
2
go.mod
2
go.mod
|
@ -29,7 +29,7 @@ require (
|
||||||
github.com/stretchr/testify v1.9.0
|
github.com/stretchr/testify v1.9.0
|
||||||
golang.org/x/sys v0.26.0
|
golang.org/x/sys v0.26.0
|
||||||
gopkg.in/evanphx/json-patch.v4 v4.12.0
|
gopkg.in/evanphx/json-patch.v4 v4.12.0
|
||||||
k8s.io/api v0.0.0-20241105070142-433e4b64e6cd
|
k8s.io/api v0.0.0-20241105190150-f8a03b70471d
|
||||||
k8s.io/apimachinery v0.0.0-20241104225908-9500acc2d964
|
k8s.io/apimachinery v0.0.0-20241104225908-9500acc2d964
|
||||||
k8s.io/cli-runtime v0.0.0-20241105073514-8ceafc062481
|
k8s.io/cli-runtime v0.0.0-20241105073514-8ceafc062481
|
||||||
k8s.io/client-go v0.0.0-20241105070536-3fc0d17041aa
|
k8s.io/client-go v0.0.0-20241105070536-3fc0d17041aa
|
||||||
|
|
4
go.sum
4
go.sum
|
@ -204,8 +204,8 @@ gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
||||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
k8s.io/api v0.0.0-20241105070142-433e4b64e6cd h1:bv8oW58STfMydUY5pCrXH0DPrEURaT30WA3kBDuZhgA=
|
k8s.io/api v0.0.0-20241105190150-f8a03b70471d h1:EwEn0EIgQsqmOFePtapzccbyjZZPNZWyOazAYseLzqk=
|
||||||
k8s.io/api v0.0.0-20241105070142-433e4b64e6cd/go.mod h1:mp+gO7jvg9YbSvPU5PHKqKtHXwF5DBApTCw7TFflWqU=
|
k8s.io/api v0.0.0-20241105190150-f8a03b70471d/go.mod h1:mp+gO7jvg9YbSvPU5PHKqKtHXwF5DBApTCw7TFflWqU=
|
||||||
k8s.io/apimachinery v0.0.0-20241104225908-9500acc2d964 h1:kNmV/yxcgj6VWL2DDn4jANbDt7vjHTd342ZmSQG3xi4=
|
k8s.io/apimachinery v0.0.0-20241104225908-9500acc2d964 h1:kNmV/yxcgj6VWL2DDn4jANbDt7vjHTd342ZmSQG3xi4=
|
||||||
k8s.io/apimachinery v0.0.0-20241104225908-9500acc2d964/go.mod h1:RBz1atosgwQyw4A8TzwjTQDnBVo/eak+3xLfOQr/By8=
|
k8s.io/apimachinery v0.0.0-20241104225908-9500acc2d964/go.mod h1:RBz1atosgwQyw4A8TzwjTQDnBVo/eak+3xLfOQr/By8=
|
||||||
k8s.io/cli-runtime v0.0.0-20241105073514-8ceafc062481 h1:LI/LTUpRCev3vLSngIjivjYrVfcrDjCIC7YamJgnOAU=
|
k8s.io/cli-runtime v0.0.0-20241105073514-8ceafc062481 h1:LI/LTUpRCev3vLSngIjivjYrVfcrDjCIC7YamJgnOAU=
|
||||||
|
|
|
@ -56,6 +56,9 @@ func WithBuiltinTemplateFuncs(tmpl *template.Template) *template.Template {
|
||||||
return "", errors.New(message)
|
return "", errors.New(message)
|
||||||
},
|
},
|
||||||
"wrap": func(l int, s string) (string, error) {
|
"wrap": func(l int, s string) (string, error) {
|
||||||
|
// realign all line breaks
|
||||||
|
s = strings.ReplaceAll(s, "\n", "")
|
||||||
|
|
||||||
buf := bytes.NewBuffer(nil)
|
buf := bytes.NewBuffer(nil)
|
||||||
writer := term.NewWordWrapWriter(buf, uint(l))
|
writer := term.NewWordWrapWriter(buf, uint(l))
|
||||||
_, err := writer.Write([]byte(s))
|
_, err := writer.Write([]byte(s))
|
||||||
|
|
|
@ -56,6 +56,13 @@ func TestFuncs(t *testing.T) {
|
||||||
Context: "this/is/a/slash/separated/thing",
|
Context: "this/is/a/slash/separated/thing",
|
||||||
Expect: "[this is a slash separated thing]",
|
Expect: "[this is a slash separated thing]",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Name: "realign line breaks",
|
||||||
|
FuncName: "wrap",
|
||||||
|
Source: `{{wrap 76 .}}`,
|
||||||
|
Context: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus pulvinar in libero id sagittis. \nAliquam sem enim, vehicula et urna ac, vehicula ullamcorper sem. Morbi turpis arcu, aliquet at \neros quis, sodales dignissim eros. \nQuisque ut lectus quis magna maximus elementum a nec felis. \nNulla ultricies pulvinar quam, id tincidunt.",
|
||||||
|
Expect: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus pulvinar in\nlibero id sagittis. Aliquam sem enim, vehicula et urna ac, vehicula\nullamcorper sem. Morbi turpis arcu, aliquet at eros quis, sodales dignissim\neros. Quisque ut lectus quis magna maximus elementum a nec felis. Nulla\nultricies pulvinar quam, id tincidunt.",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Name: "basic",
|
Name: "basic",
|
||||||
FuncName: "join",
|
FuncName: "join",
|
||||||
|
|
Loading…
Reference in New Issue