From eb139f4572c60a26f1e46feca45f8b23865aeada Mon Sep 17 00:00:00 2001 From: Tomas Nozicka Date: Fri, 2 Jun 2017 13:56:47 +0200 Subject: [PATCH] Lookup --no-headers flag safely in PrinterForCommand function --- pkg/kubectl/cmd/util/printing.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pkg/kubectl/cmd/util/printing.go b/pkg/kubectl/cmd/util/printing.go index 8e2c0785fff..a0b753ca08b 100644 --- a/pkg/kubectl/cmd/util/printing.go +++ b/pkg/kubectl/cmd/util/printing.go @@ -115,8 +115,13 @@ func PrinterForCommand(cmd *cobra.Command, outputOpts *printers.OutputOptions, m outputOpts = extractOutputOptions(cmd) } - printer, err := printers.GetStandardPrinter(outputOpts, - GetFlagBool(cmd, "no-headers"), mapper, typer, encoder, decoders, options) + // this function may be invoked by a command that did not call AddPrinterFlags first, so we need + // to be safe about how we access the no-headers flag + noHeaders := false + if cmd.Flags().Lookup("no-headers") != nil { + noHeaders = GetFlagBool(cmd, "no-headers") + } + printer, err := printers.GetStandardPrinter(outputOpts, noHeaders, mapper, typer, encoder, decoders, options) if err != nil { return nil, err }