mirror of https://github.com/k3s-io/k3s
Use tabwriter with remembered column widths
parent
096186afb5
commit
2b1a2d361f
|
@ -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 (
|
||||||
"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(
|
||||||
"//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 (
|
||||||
"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
|
||||||
|
|
||||||
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
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
|
||||||
|
|
|
@ -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
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
"text/tabwriter"
|
|
||||||
|
"github.com/liggitt/tabwriter"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
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(
|
||||||
"//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 (
|
||||||
"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
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
"text/tabwriter"
|
|
||||||
|
"github.com/liggitt/tabwriter"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
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.
|
||||||
|
|
Loading…
Reference in New Issue