mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-01 07:47:56 +00:00
Rename NewHumanReadablePrinter to NewTablePrinter
This commit is contained in:
parent
306740f81c
commit
bbc2886a3b
@ -87,7 +87,7 @@ func (f *HumanPrintFlags) ToPrinter(outputFormat string) (printers.ResourcePrint
|
|||||||
columnLabels = *f.ColumnLabels
|
columnLabels = *f.ColumnLabels
|
||||||
}
|
}
|
||||||
|
|
||||||
p := printers.NewHumanReadablePrinter(printers.PrintOptions{
|
p := printers.NewTablePrinter(printers.PrintOptions{
|
||||||
Kind: f.Kind,
|
Kind: f.Kind,
|
||||||
WithKind: showKind,
|
WithKind: showKind,
|
||||||
NoHeaders: f.NoHeaders,
|
NoHeaders: f.NoHeaders,
|
||||||
|
@ -171,7 +171,7 @@ func TestPrintUnstructuredObject(t *testing.T) {
|
|||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
out.Reset()
|
out.Reset()
|
||||||
printer := printers.NewHumanReadablePrinter(test.options).With(AddDefaultHandlers)
|
printer := printers.NewTablePrinter(test.options).With(AddDefaultHandlers)
|
||||||
printer.PrintObj(test.object, out)
|
printer.PrintObj(test.object, out)
|
||||||
|
|
||||||
matches, err := regexp.MatchString(test.expected, out.String())
|
matches, err := regexp.MatchString(test.expected, out.String())
|
||||||
@ -299,7 +299,7 @@ func ErrorPrintHandler(obj *TestPrintType, options printers.PrintOptions) ([]met
|
|||||||
|
|
||||||
func TestCustomTypePrinting(t *testing.T) {
|
func TestCustomTypePrinting(t *testing.T) {
|
||||||
columns := []metav1beta1.TableColumnDefinition{{Name: "Data"}}
|
columns := []metav1beta1.TableColumnDefinition{{Name: "Data"}}
|
||||||
printer := printers.NewHumanReadablePrinter(printers.PrintOptions{})
|
printer := printers.NewTablePrinter(printers.PrintOptions{})
|
||||||
printer.TableHandler(columns, PrintCustomType)
|
printer.TableHandler(columns, PrintCustomType)
|
||||||
|
|
||||||
obj := TestPrintType{"test object"}
|
obj := TestPrintType{"test object"}
|
||||||
@ -316,7 +316,7 @@ func TestCustomTypePrinting(t *testing.T) {
|
|||||||
|
|
||||||
func TestPrintHandlerError(t *testing.T) {
|
func TestPrintHandlerError(t *testing.T) {
|
||||||
columns := []metav1beta1.TableColumnDefinition{{Name: "Data"}}
|
columns := []metav1beta1.TableColumnDefinition{{Name: "Data"}}
|
||||||
printer := printers.NewHumanReadablePrinter(printers.PrintOptions{})
|
printer := printers.NewTablePrinter(printers.PrintOptions{})
|
||||||
printer.TableHandler(columns, ErrorPrintHandler)
|
printer.TableHandler(columns, ErrorPrintHandler)
|
||||||
obj := TestPrintType{"test object"}
|
obj := TestPrintType{"test object"}
|
||||||
buffer := &bytes.Buffer{}
|
buffer := &bytes.Buffer{}
|
||||||
@ -327,7 +327,7 @@ func TestPrintHandlerError(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestUnknownTypePrinting(t *testing.T) {
|
func TestUnknownTypePrinting(t *testing.T) {
|
||||||
printer := printers.NewHumanReadablePrinter(printers.PrintOptions{})
|
printer := printers.NewTablePrinter(printers.PrintOptions{})
|
||||||
buffer := &bytes.Buffer{}
|
buffer := &bytes.Buffer{}
|
||||||
err := printer.PrintObj(&TestUnknownType{}, buffer)
|
err := printer.PrintObj(&TestUnknownType{}, buffer)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
@ -588,10 +588,10 @@ func TestPrinters(t *testing.T) {
|
|||||||
|
|
||||||
// a humanreadable printer deals with internal-versioned objects
|
// a humanreadable printer deals with internal-versioned objects
|
||||||
humanReadablePrinter := map[string]printers.ResourcePrinter{
|
humanReadablePrinter := map[string]printers.ResourcePrinter{
|
||||||
"humanReadable": printers.NewHumanReadablePrinter(printers.PrintOptions{
|
"humanReadable": printers.NewTablePrinter(printers.PrintOptions{
|
||||||
NoHeaders: true,
|
NoHeaders: true,
|
||||||
}),
|
}),
|
||||||
"humanReadableHeaders": printers.NewHumanReadablePrinter(printers.PrintOptions{}),
|
"humanReadableHeaders": printers.NewTablePrinter(printers.PrintOptions{}),
|
||||||
}
|
}
|
||||||
AddHandlers((humanReadablePrinter["humanReadable"]).(*printers.HumanReadablePrinter))
|
AddHandlers((humanReadablePrinter["humanReadable"]).(*printers.HumanReadablePrinter))
|
||||||
AddHandlers((humanReadablePrinter["humanReadableHeaders"]).(*printers.HumanReadablePrinter))
|
AddHandlers((humanReadablePrinter["humanReadableHeaders"]).(*printers.HumanReadablePrinter))
|
||||||
@ -611,7 +611,7 @@ func TestPrinters(t *testing.T) {
|
|||||||
|
|
||||||
func TestPrintEventsResultSorted(t *testing.T) {
|
func TestPrintEventsResultSorted(t *testing.T) {
|
||||||
// Arrange
|
// Arrange
|
||||||
printer := printers.NewHumanReadablePrinter(printers.PrintOptions{})
|
printer := printers.NewTablePrinter(printers.PrintOptions{})
|
||||||
AddHandlers(printer)
|
AddHandlers(printer)
|
||||||
|
|
||||||
obj := api.EventList{
|
obj := api.EventList{
|
||||||
@ -656,7 +656,7 @@ func TestPrintEventsResultSorted(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestPrintNodeStatus(t *testing.T) {
|
func TestPrintNodeStatus(t *testing.T) {
|
||||||
printer := printers.NewHumanReadablePrinter(printers.PrintOptions{})
|
printer := printers.NewTablePrinter(printers.PrintOptions{})
|
||||||
AddHandlers(printer)
|
AddHandlers(printer)
|
||||||
table := []struct {
|
table := []struct {
|
||||||
node api.Node
|
node api.Node
|
||||||
@ -746,7 +746,7 @@ func TestPrintNodeStatus(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestPrintNodeRole(t *testing.T) {
|
func TestPrintNodeRole(t *testing.T) {
|
||||||
printer := printers.NewHumanReadablePrinter(printers.PrintOptions{})
|
printer := printers.NewTablePrinter(printers.PrintOptions{})
|
||||||
AddHandlers(printer)
|
AddHandlers(printer)
|
||||||
table := []struct {
|
table := []struct {
|
||||||
node api.Node
|
node api.Node
|
||||||
@ -791,7 +791,7 @@ func TestPrintNodeRole(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestPrintNodeOSImage(t *testing.T) {
|
func TestPrintNodeOSImage(t *testing.T) {
|
||||||
printer := printers.NewHumanReadablePrinter(printers.PrintOptions{
|
printer := printers.NewTablePrinter(printers.PrintOptions{
|
||||||
ColumnLabels: []string{},
|
ColumnLabels: []string{},
|
||||||
Wide: true,
|
Wide: true,
|
||||||
})
|
})
|
||||||
@ -836,7 +836,7 @@ func TestPrintNodeOSImage(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestPrintNodeKernelVersion(t *testing.T) {
|
func TestPrintNodeKernelVersion(t *testing.T) {
|
||||||
printer := printers.NewHumanReadablePrinter(printers.PrintOptions{
|
printer := printers.NewTablePrinter(printers.PrintOptions{
|
||||||
ColumnLabels: []string{},
|
ColumnLabels: []string{},
|
||||||
Wide: true,
|
Wide: true,
|
||||||
})
|
})
|
||||||
@ -881,7 +881,7 @@ func TestPrintNodeKernelVersion(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestPrintNodeContainerRuntimeVersion(t *testing.T) {
|
func TestPrintNodeContainerRuntimeVersion(t *testing.T) {
|
||||||
printer := printers.NewHumanReadablePrinter(printers.PrintOptions{
|
printer := printers.NewTablePrinter(printers.PrintOptions{
|
||||||
ColumnLabels: []string{},
|
ColumnLabels: []string{},
|
||||||
Wide: true,
|
Wide: true,
|
||||||
})
|
})
|
||||||
@ -926,7 +926,7 @@ func TestPrintNodeContainerRuntimeVersion(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestPrintNodeName(t *testing.T) {
|
func TestPrintNodeName(t *testing.T) {
|
||||||
printer := printers.NewHumanReadablePrinter(printers.PrintOptions{
|
printer := printers.NewTablePrinter(printers.PrintOptions{
|
||||||
Wide: true,
|
Wide: true,
|
||||||
})
|
})
|
||||||
AddHandlers(printer)
|
AddHandlers(printer)
|
||||||
@ -963,7 +963,7 @@ func TestPrintNodeName(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestPrintNodeExternalIP(t *testing.T) {
|
func TestPrintNodeExternalIP(t *testing.T) {
|
||||||
printer := printers.NewHumanReadablePrinter(printers.PrintOptions{
|
printer := printers.NewTablePrinter(printers.PrintOptions{
|
||||||
Wide: true,
|
Wide: true,
|
||||||
})
|
})
|
||||||
AddHandlers(printer)
|
AddHandlers(printer)
|
||||||
@ -1011,7 +1011,7 @@ func TestPrintNodeExternalIP(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestPrintNodeInternalIP(t *testing.T) {
|
func TestPrintNodeInternalIP(t *testing.T) {
|
||||||
printer := printers.NewHumanReadablePrinter(printers.PrintOptions{
|
printer := printers.NewTablePrinter(printers.PrintOptions{
|
||||||
Wide: true,
|
Wide: true,
|
||||||
})
|
})
|
||||||
AddHandlers(printer)
|
AddHandlers(printer)
|
||||||
@ -1419,7 +1419,7 @@ func TestPrintHumanReadableWithNamespace(t *testing.T) {
|
|||||||
for i, test := range table {
|
for i, test := range table {
|
||||||
if test.isNamespaced {
|
if test.isNamespaced {
|
||||||
// Expect output to include namespace when requested.
|
// Expect output to include namespace when requested.
|
||||||
printer := printers.NewHumanReadablePrinter(printers.PrintOptions{
|
printer := printers.NewTablePrinter(printers.PrintOptions{
|
||||||
WithNamespace: true,
|
WithNamespace: true,
|
||||||
})
|
})
|
||||||
AddHandlers(printer)
|
AddHandlers(printer)
|
||||||
@ -1434,7 +1434,7 @@ func TestPrintHumanReadableWithNamespace(t *testing.T) {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Expect error when trying to get all namespaces for un-namespaced object.
|
// Expect error when trying to get all namespaces for un-namespaced object.
|
||||||
printer := printers.NewHumanReadablePrinter(printers.PrintOptions{
|
printer := printers.NewTablePrinter(printers.PrintOptions{
|
||||||
WithNamespace: true,
|
WithNamespace: true,
|
||||||
})
|
})
|
||||||
buffer := &bytes.Buffer{}
|
buffer := &bytes.Buffer{}
|
||||||
@ -1513,7 +1513,7 @@ func TestPrintPodTable(t *testing.T) {
|
|||||||
}
|
}
|
||||||
verifyTable(t, table)
|
verifyTable(t, table)
|
||||||
buf := &bytes.Buffer{}
|
buf := &bytes.Buffer{}
|
||||||
p := printers.NewHumanReadablePrinter(test.opts).With(AddHandlers)
|
p := printers.NewTablePrinter(test.opts).With(AddHandlers)
|
||||||
if err := p.PrintObj(table, buf); err != nil {
|
if err := p.PrintObj(table, buf); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -34,10 +34,10 @@ var _ ResourcePrinter = &HumanReadablePrinter{}
|
|||||||
|
|
||||||
var withNamespacePrefixColumns = []string{"NAMESPACE"} // TODO(erictune): print cluster name too.
|
var withNamespacePrefixColumns = []string{"NAMESPACE"} // TODO(erictune): print cluster name too.
|
||||||
|
|
||||||
// NewHumanReadablePrinter creates a printer suitable for calling PrintObj().
|
// NewTablePrinter creates a printer suitable for calling PrintObj().
|
||||||
// TODO(seans3): Change return type to ResourcePrinter interface once we no longer need
|
// TODO(seans3): Change return type to ResourcePrinter interface once we no longer need
|
||||||
// to constuct the "handlerMap".
|
// to constuct the "handlerMap".
|
||||||
func NewHumanReadablePrinter(options PrintOptions) *HumanReadablePrinter {
|
func NewTablePrinter(options PrintOptions) *HumanReadablePrinter {
|
||||||
printer := &HumanReadablePrinter{
|
printer := &HumanReadablePrinter{
|
||||||
handlerMap: make(map[reflect.Type]*handlerEntry),
|
handlerMap: make(map[reflect.Type]*handlerEntry),
|
||||||
options: options,
|
options: options,
|
||||||
|
Loading…
Reference in New Issue
Block a user