mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 13:37:30 +00:00
Lookup --no-headers flag safely in PrinterForCommand function
This commit is contained in:
parent
b84567a57e
commit
eb139f4572
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user