From 78ccf2dd52f0195acd0dd921b679d7a7d56c9312 Mon Sep 17 00:00:00 2001 From: juanvallejo Date: Wed, 18 Jan 2017 17:58:14 -0500 Subject: [PATCH] Add printer#EnsurePrintHeaders method This patch adds a new `EnsurePrintHeaders` method to the HumanReadablePrinter `ResourcePrinter`, which allows headers to be printed in cases where multiple lists of the same resource are printed consecutively, but are separated by non-printer related information. --- pkg/kubectl/resource_printer.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pkg/kubectl/resource_printer.go b/pkg/kubectl/resource_printer.go index b09dba33222..4cf7c5fc45d 100644 --- a/pkg/kubectl/resource_printer.go +++ b/pkg/kubectl/resource_printer.go @@ -419,6 +419,15 @@ func (h *HumanReadablePrinter) EnsurePrintWithKind(kind string) { h.options.Kind = kind } +// EnsurePrintHeaders sets the HumanReadablePrinter option "NoHeaders" to false +// and removes the .lastType that was printed, which forces headers to be +// printed in cases where multiple lists of the same resource are printed +// consecutively, but are separated by non-printer related information. +func (h *HumanReadablePrinter) EnsurePrintHeaders() { + h.options.NoHeaders = false + h.lastType = nil +} + // Handler adds a print handler with a given set of columns to HumanReadablePrinter instance. // See validatePrintHandlerFunc for required method signature. func (h *HumanReadablePrinter) Handler(columns, columnsWithWide []string, printFunc interface{}) error {