Merge pull request #46852 from tnozicka/lookup-no-headers-safely
Automatic merge from submit-queue (batch tested with PRs 47470, 47260, 47411, 46852, 46135) Lookup --no-headers flag safely in PrinterForCommand function If this was invoked by a command that did not call AddPrinterFlags first, it ended up with fatal error on `GetFlagBool(cmd, "no-headers")`. This is causing a bug in OpenShift's command reusing this code and not actually having a flag `--no-headers`.
This commit is contained in:
		@@ -115,8 +115,13 @@ func PrinterForCommand(cmd *cobra.Command, outputOpts *printers.OutputOptions, m
 | 
				
			|||||||
		outputOpts = extractOutputOptions(cmd)
 | 
							outputOpts = extractOutputOptions(cmd)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	printer, err := printers.GetStandardPrinter(outputOpts,
 | 
						// this function may be invoked by a command that did not call AddPrinterFlags first, so we need
 | 
				
			||||||
		GetFlagBool(cmd, "no-headers"), mapper, typer, encoder, decoders, options)
 | 
						// 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 {
 | 
						if err != nil {
 | 
				
			||||||
		return nil, err
 | 
							return nil, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user