Unverified Commit aef11799 authored by Kubernetes Prow Robot's avatar Kubernetes Prow Robot Committed by GitHub

Merge pull request #72418 from liggitt/align-watch-output

fix tabwriter to remember column widths, align `kubectl get -w` output
parents fb1a8307 2b1a2d36
...@@ -2446,6 +2446,10 @@ ...@@ -2446,6 +2446,10 @@
"Rev": "093a0c3888753c2056e7373183693d670c6bba01" "Rev": "093a0c3888753c2056e7373183693d670c6bba01"
}, },
{ {
"ImportPath": "github.com/liggitt/tabwriter",
"Rev": "89fcab3d43de07060e4fd4c1547430ed57e87f24"
},
{
"ImportPath": "github.com/magiconair/properties", "ImportPath": "github.com/magiconair/properties",
"Comment": "v1.7.0-4-g61b492c03cf472", "Comment": "v1.7.0-4-g61b492c03cf472",
"Rev": "61b492c03cf472e0c6419be5899b8e0dc28b1b88" "Rev": "61b492c03cf472e0c6419be5899b8e0dc28b1b88"
......
...@@ -74954,6 +74954,41 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI ...@@ -74954,6 +74954,41 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
================================================================================ ================================================================================
= vendor/github.com/liggitt/tabwriter licensed under: =
Copyright (c) 2009 The Go Authors. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
= vendor/github.com/liggitt/tabwriter/LICENSE 5d4950ecb7b26d2c5e4e7b4e0dd74707
================================================================================
================================================================================
= vendor/github.com/magiconair/properties licensed under: = = vendor/github.com/magiconair/properties licensed under: =
goproperties - properties file decoder for Go goproperties - properties file decoder for Go
...@@ -41,6 +41,7 @@ go_library( ...@@ -41,6 +41,7 @@ go_library(
"//staging/src/k8s.io/client-go/tools/clientcmd:go_default_library", "//staging/src/k8s.io/client-go/tools/clientcmd:go_default_library",
"//staging/src/k8s.io/client-go/tools/clientcmd/api:go_default_library", "//staging/src/k8s.io/client-go/tools/clientcmd/api:go_default_library",
"//staging/src/k8s.io/client-go/tools/clientcmd/api/latest:go_default_library", "//staging/src/k8s.io/client-go/tools/clientcmd/api/latest:go_default_library",
"//vendor/github.com/liggitt/tabwriter:go_default_library",
"//vendor/github.com/spf13/cobra:go_default_library", "//vendor/github.com/spf13/cobra:go_default_library",
], ],
) )
......
...@@ -21,8 +21,8 @@ import ( ...@@ -21,8 +21,8 @@ import (
"io" "io"
"sort" "sort"
"strings" "strings"
"text/tabwriter"
"github.com/liggitt/tabwriter"
"github.com/spf13/cobra" "github.com/spf13/cobra"
utilerrors "k8s.io/apimachinery/pkg/util/errors" utilerrors "k8s.io/apimachinery/pkg/util/errors"
......
...@@ -55,6 +55,7 @@ go_library( ...@@ -55,6 +55,7 @@ go_library(
"//staging/src/k8s.io/client-go/tools/watch:go_default_library", "//staging/src/k8s.io/client-go/tools/watch:go_default_library",
"//staging/src/k8s.io/client-go/util/integer:go_default_library", "//staging/src/k8s.io/client-go/util/integer:go_default_library",
"//staging/src/k8s.io/client-go/util/jsonpath:go_default_library", "//staging/src/k8s.io/client-go/util/jsonpath:go_default_library",
"//vendor/github.com/liggitt/tabwriter:go_default_library",
"//vendor/github.com/spf13/cobra:go_default_library", "//vendor/github.com/spf13/cobra:go_default_library",
"//vendor/k8s.io/klog:go_default_library", "//vendor/k8s.io/klog:go_default_library",
"//vendor/vbom.ml/util/sortorder:go_default_library", "//vendor/vbom.ml/util/sortorder:go_default_library",
......
...@@ -24,7 +24,8 @@ import ( ...@@ -24,7 +24,8 @@ import (
"reflect" "reflect"
"regexp" "regexp"
"strings" "strings"
"text/tabwriter"
"github.com/liggitt/tabwriter"
"k8s.io/apimachinery/pkg/api/meta" "k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
......
...@@ -537,6 +537,7 @@ func (o *GetOptions) Run(f cmdutil.Factory, cmd *cobra.Command, args []string) e ...@@ -537,6 +537,7 @@ func (o *GetOptions) Run(f cmdutil.Factory, cmd *cobra.Command, args []string) e
if shouldGetNewPrinterForMapping(printer, lastMapping, mapping) { if shouldGetNewPrinterForMapping(printer, lastMapping, mapping) {
w.Flush() w.Flush()
w.SetRememberedWidths(nil)
// TODO: this doesn't belong here // TODO: this doesn't belong here
// add linebreak between resource groups (if there is more than one) // add linebreak between resource groups (if there is more than one)
...@@ -654,10 +655,11 @@ func (o *GetOptions) watch(f cmdutil.Factory, cmd *cobra.Command, args []string) ...@@ -654,10 +655,11 @@ func (o *GetOptions) watch(f cmdutil.Factory, cmd *cobra.Command, args []string)
} }
} }
writer := utilprinters.GetNewTabWriter(o.Out)
// print the current object // print the current object
if !o.WatchOnly { if !o.WatchOnly {
var objsToPrint []runtime.Object var objsToPrint []runtime.Object
writer := utilprinters.GetNewTabWriter(o.Out)
if isList { if isList {
objsToPrint, _ = meta.ExtractList(obj) objsToPrint, _ = meta.ExtractList(obj)
...@@ -702,9 +704,10 @@ func (o *GetOptions) watch(f cmdutil.Factory, cmd *cobra.Command, args []string) ...@@ -702,9 +704,10 @@ func (o *GetOptions) watch(f cmdutil.Factory, cmd *cobra.Command, args []string)
internalGV := mapping.GroupVersionKind.GroupKind().WithVersion(runtime.APIVersionInternal).GroupVersion() internalGV := mapping.GroupVersionKind.GroupKind().WithVersion(runtime.APIVersionInternal).GroupVersion()
objToPrint = attemptToConvertToInternal(e.Object, legacyscheme.Scheme, internalGV) objToPrint = attemptToConvertToInternal(e.Object, legacyscheme.Scheme, internalGV)
} }
if err := printer.PrintObj(objToPrint, o.Out); err != nil { if err := printer.PrintObj(objToPrint, writer); err != nil {
return false, err return false, err
} }
writer.Flush()
return false, nil return false, nil
}) })
return err return err
......
...@@ -1211,8 +1211,8 @@ func TestWatchLabelSelector(t *testing.T) { ...@@ -1211,8 +1211,8 @@ func TestWatchLabelSelector(t *testing.T) {
expected := `NAME READY STATUS RESTARTS AGE expected := `NAME READY STATUS RESTARTS AGE
bar 0/0 0 <unknown> bar 0/0 0 <unknown>
foo 0/0 0 <unknown> foo 0/0 0 <unknown>
foo 0/0 0 <unknown> foo 0/0 0 <unknown>
foo 0/0 0 <unknown> foo 0/0 0 <unknown>
` `
if e, a := expected, buf.String(); e != a { if e, a := expected, buf.String(); e != a {
t.Errorf("expected\n%v\ngot\n%v", e, a) t.Errorf("expected\n%v\ngot\n%v", e, a)
...@@ -1262,8 +1262,8 @@ func TestWatchFieldSelector(t *testing.T) { ...@@ -1262,8 +1262,8 @@ func TestWatchFieldSelector(t *testing.T) {
expected := `NAME READY STATUS RESTARTS AGE expected := `NAME READY STATUS RESTARTS AGE
bar 0/0 0 <unknown> bar 0/0 0 <unknown>
foo 0/0 0 <unknown> foo 0/0 0 <unknown>
foo 0/0 0 <unknown> foo 0/0 0 <unknown>
foo 0/0 0 <unknown> foo 0/0 0 <unknown>
` `
if e, a := expected, buf.String(); e != a { if e, a := expected, buf.String(); e != a {
t.Errorf("expected\n%v\ngot\n%v", e, a) t.Errorf("expected\n%v\ngot\n%v", e, a)
...@@ -1305,8 +1305,8 @@ func TestWatchResource(t *testing.T) { ...@@ -1305,8 +1305,8 @@ func TestWatchResource(t *testing.T) {
expected := `NAME READY STATUS RESTARTS AGE expected := `NAME READY STATUS RESTARTS AGE
foo 0/0 0 <unknown> foo 0/0 0 <unknown>
foo 0/0 0 <unknown> foo 0/0 0 <unknown>
foo 0/0 0 <unknown> foo 0/0 0 <unknown>
` `
if e, a := expected, buf.String(); e != a { if e, a := expected, buf.String(); e != a {
t.Errorf("expected\n%v\ngot\n%v", e, a) t.Errorf("expected\n%v\ngot\n%v", e, a)
...@@ -1349,8 +1349,8 @@ func TestWatchResourceIdentifiedByFile(t *testing.T) { ...@@ -1349,8 +1349,8 @@ func TestWatchResourceIdentifiedByFile(t *testing.T) {
expected := `NAME READY STATUS RESTARTS AGE expected := `NAME READY STATUS RESTARTS AGE
foo 0/0 0 <unknown> foo 0/0 0 <unknown>
foo 0/0 0 <unknown> foo 0/0 0 <unknown>
foo 0/0 0 <unknown> foo 0/0 0 <unknown>
` `
if e, a := expected, buf.String(); e != a { if e, a := expected, buf.String(); e != a {
t.Errorf("expected\n%v\ngot\n%v", e, a) t.Errorf("expected\n%v\ngot\n%v", e, a)
...@@ -1392,7 +1392,7 @@ func TestWatchOnlyResource(t *testing.T) { ...@@ -1392,7 +1392,7 @@ func TestWatchOnlyResource(t *testing.T) {
expected := `NAME READY STATUS RESTARTS AGE expected := `NAME READY STATUS RESTARTS AGE
foo 0/0 0 <unknown> foo 0/0 0 <unknown>
foo 0/0 0 <unknown> foo 0/0 0 <unknown>
` `
if e, a := expected, buf.String(); e != a { if e, a := expected, buf.String(); e != a {
t.Errorf("expected\n%v\ngot\n%v", e, a) t.Errorf("expected\n%v\ngot\n%v", e, a)
...@@ -1437,7 +1437,7 @@ func TestWatchOnlyList(t *testing.T) { ...@@ -1437,7 +1437,7 @@ func TestWatchOnlyList(t *testing.T) {
expected := `NAME READY STATUS RESTARTS AGE expected := `NAME READY STATUS RESTARTS AGE
foo 0/0 0 <unknown> foo 0/0 0 <unknown>
foo 0/0 0 <unknown> foo 0/0 0 <unknown>
` `
if e, a := expected, buf.String(); e != a { if e, a := expected, buf.String(); e != a {
t.Errorf("expected\n%v\ngot\n%v", e, a) t.Errorf("expected\n%v\ngot\n%v", e, a)
......
...@@ -5,6 +5,7 @@ go_library( ...@@ -5,6 +5,7 @@ go_library(
srcs = ["tabwriter.go"], srcs = ["tabwriter.go"],
importpath = "k8s.io/kubernetes/pkg/kubectl/util/printers", importpath = "k8s.io/kubernetes/pkg/kubectl/util/printers",
visibility = ["//visibility:public"], visibility = ["//visibility:public"],
deps = ["//vendor/github.com/liggitt/tabwriter:go_default_library"],
) )
filegroup( filegroup(
......
...@@ -18,7 +18,8 @@ package printers ...@@ -18,7 +18,8 @@ package printers
import ( import (
"io" "io"
"text/tabwriter"
"github.com/liggitt/tabwriter"
) )
const ( const (
...@@ -26,7 +27,7 @@ const ( ...@@ -26,7 +27,7 @@ const (
tabwriterWidth = 4 tabwriterWidth = 4
tabwriterPadding = 3 tabwriterPadding = 3
tabwriterPadChar = ' ' tabwriterPadChar = ' '
tabwriterFlags = 0 tabwriterFlags = tabwriter.RememberWidths
) )
// GetNewTabWriter returns a tabwriter that translates tabbed columns in input into properly aligned text. // GetNewTabWriter returns a tabwriter that translates tabbed columns in input into properly aligned text.
......
...@@ -23,6 +23,7 @@ go_library( ...@@ -23,6 +23,7 @@ go_library(
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/runtime/schema:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/util/runtime:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/util/runtime:go_default_library",
"//vendor/github.com/liggitt/tabwriter:go_default_library",
], ],
) )
......
...@@ -22,7 +22,8 @@ import ( ...@@ -22,7 +22,8 @@ import (
"io" "io"
"reflect" "reflect"
"strings" "strings"
"text/tabwriter"
"github.com/liggitt/tabwriter"
"k8s.io/apimachinery/pkg/api/meta" "k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
......
...@@ -18,7 +18,8 @@ package printers ...@@ -18,7 +18,8 @@ package printers
import ( import (
"io" "io"
"text/tabwriter"
"github.com/liggitt/tabwriter"
) )
const ( const (
...@@ -26,7 +27,7 @@ const ( ...@@ -26,7 +27,7 @@ const (
tabwriterWidth = 4 tabwriterWidth = 4
tabwriterPadding = 3 tabwriterPadding = 3
tabwriterPadChar = ' ' tabwriterPadChar = ' '
tabwriterFlags = 0 tabwriterFlags = tabwriter.RememberWidths
) )
// GetNewTabWriter returns a tabwriter that translates tabbed columns in input into properly aligned text. // GetNewTabWriter returns a tabwriter that translates tabbed columns in input into properly aligned text.
......
...@@ -299,6 +299,7 @@ filegroup( ...@@ -299,6 +299,7 @@ filegroup(
"//vendor/github.com/libopenstorage/openstorage/pkg/parser:all-srcs", "//vendor/github.com/libopenstorage/openstorage/pkg/parser:all-srcs",
"//vendor/github.com/libopenstorage/openstorage/pkg/units:all-srcs", "//vendor/github.com/libopenstorage/openstorage/pkg/units:all-srcs",
"//vendor/github.com/libopenstorage/openstorage/volume:all-srcs", "//vendor/github.com/libopenstorage/openstorage/volume:all-srcs",
"//vendor/github.com/liggitt/tabwriter:all-srcs",
"//vendor/github.com/magiconair/properties:all-srcs", "//vendor/github.com/magiconair/properties:all-srcs",
"//vendor/github.com/mailru/easyjson/buffer:all-srcs", "//vendor/github.com/mailru/easyjson/buffer:all-srcs",
"//vendor/github.com/mailru/easyjson/jlexer:all-srcs", "//vendor/github.com/mailru/easyjson/jlexer:all-srcs",
......
language: go
go:
- "1.8"
- "1.9"
- "1.10"
- "1.11"
- "1.12"
- master
script: go test -v ./...
load("@io_bazel_rules_go//go:def.bzl", "go_library")
go_library(
name = "go_default_library",
srcs = ["tabwriter.go"],
importmap = "k8s.io/kubernetes/vendor/github.com/liggitt/tabwriter",
importpath = "github.com/liggitt/tabwriter",
visibility = ["//visibility:public"],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)
Copyright (c) 2009 The Go Authors. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This repo is a drop-in replacement for the golang [text/tabwriter](https://golang.org/pkg/text/tabwriter/) package.
It is based on that package at [cf2c2ea8](https://github.com/golang/go/tree/cf2c2ea89d09d486bb018b1817c5874388038c3a/src/text/tabwriter) and inherits its license.
The following additional features are supported:
* `RememberWidths` flag allows remembering maximum widths seen per column even after Flush() is called.
* `RememberedWidths() []int` and `SetRememberedWidths([]int) *Writer` allows obtaining and transferring remembered column width between writers.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment