mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 12:15:52 +00:00
pass printOpts by pointer
This commit is contained in:
parent
d3773b4b06
commit
f5ab356043
@ -82,7 +82,7 @@ func NewCmdConfigView(out, errOut io.Writer, ConfigAccess clientcmd.ConfigAccess
|
||||
}
|
||||
|
||||
printOpts := cmdutil.ExtractCmdPrintOptions(cmd, false)
|
||||
printer, err := cmdutil.PrinterForOptions(meta.NewDefaultRESTMapper(nil, nil), latest.Scheme, nil, []runtime.Decoder{latest.Codec}, *printOpts)
|
||||
printer, err := cmdutil.PrinterForOptions(meta.NewDefaultRESTMapper(nil, nil), latest.Scheme, nil, []runtime.Decoder{latest.Codec}, printOpts)
|
||||
cmdutil.CheckErr(err)
|
||||
printer = printers.NewVersionedPrinter(printer, latest.Scheme, latest.ExternalVersion)
|
||||
|
||||
|
@ -162,7 +162,7 @@ func (o *ConvertOptions) Complete(f cmdutil.Factory, out io.Writer, cmd *cobra.C
|
||||
cmd.Flags().Set("output", outputFormat)
|
||||
}
|
||||
o.encoder = f.JSONEncoder()
|
||||
o.printer, err = f.PrinterForOptions(printers.PrintOptions{})
|
||||
o.printer, err = f.PrinterForOptions(cmdutil.ExtractCmdPrintOptions(cmd, false))
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -255,7 +255,7 @@ func (options *GetOptions) Run(f cmdutil.Factory, cmd *cobra.Command, args []str
|
||||
}
|
||||
|
||||
printOpts := cmdutil.ExtractCmdPrintOptions(cmd, options.AllNamespaces)
|
||||
printer, err := f.PrinterForOptions(*printOpts)
|
||||
printer, err := f.PrinterForOptions(printOpts)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -331,11 +331,11 @@ func (options *GetOptions) Run(f cmdutil.Factory, cmd *cobra.Command, args []str
|
||||
printWithNamespace = false
|
||||
}
|
||||
|
||||
printOpts := *cmdutil.ExtractCmdPrintOptions(cmd, printWithNamespace)
|
||||
printOpts := cmdutil.ExtractCmdPrintOptions(cmd, printWithNamespace)
|
||||
// if cmd does not specify output format and useOpenAPIPrintColumnFlagLabel flag is true,
|
||||
// then get the default output options for this mapping from OpenAPI schema.
|
||||
if !cmdSpecifiesOutputFmt(cmd) && useOpenAPIPrintColumns {
|
||||
outputOptsForMappingFromOpenAPI(f, mapping, &printOpts)
|
||||
updatePrintOptionsForOpenAPI(f, mapping, printOpts)
|
||||
}
|
||||
|
||||
printer, err = f.PrinterForMapping(printOpts, mapping)
|
||||
@ -480,7 +480,7 @@ func (options *GetOptions) watch(f cmdutil.Factory, cmd *cobra.Command, args []s
|
||||
info := infos[0]
|
||||
mapping := info.ResourceMapping()
|
||||
printOpts := cmdutil.ExtractCmdPrintOptions(cmd, options.AllNamespaces)
|
||||
printer, err := f.PrinterForMapping(*printOpts, mapping)
|
||||
printer, err := f.PrinterForMapping(printOpts, mapping)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -663,8 +663,8 @@ func cmdSpecifiesOutputFmt(cmd *cobra.Command) bool {
|
||||
}
|
||||
|
||||
// outputOptsForMappingFromOpenAPI looks for the output format metatadata in the
|
||||
// openapi schema and returns the output options for the mapping if found.
|
||||
func outputOptsForMappingFromOpenAPI(f cmdutil.Factory, mapping *meta.RESTMapping, printOpts *printers.PrintOptions) bool {
|
||||
// openapi schema and modifies the passed print options for the mapping if found.
|
||||
func updatePrintOptionsForOpenAPI(f cmdutil.Factory, mapping *meta.RESTMapping, printOpts *printers.PrintOptions) bool {
|
||||
|
||||
// user has not specified any output format, check if OpenAPI has
|
||||
// default specification to print this resource type
|
||||
|
@ -352,17 +352,17 @@ func (f *FakeFactory) Describer(*meta.RESTMapping) (printers.Describer, error) {
|
||||
return f.tf.Describer, f.tf.Err
|
||||
}
|
||||
|
||||
func (f *FakeFactory) PrinterForOptions(options printers.PrintOptions) (printers.ResourcePrinter, error) {
|
||||
func (f *FakeFactory) PrinterForOptions(options *printers.PrintOptions) (printers.ResourcePrinter, error) {
|
||||
return f.tf.Printer, f.tf.Err
|
||||
}
|
||||
|
||||
func (f *FakeFactory) PrintResourceInfoForCommand(cmd *cobra.Command, info *resource.Info, out io.Writer) error {
|
||||
printer, err := f.PrinterForOptions(printers.PrintOptions{})
|
||||
printer, err := f.PrinterForOptions(&printers.PrintOptions{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !printer.IsGeneric() {
|
||||
printer, err = f.PrinterForMapping(printers.PrintOptions{}, nil)
|
||||
printer, err = f.PrinterForMapping(&printers.PrintOptions{}, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -513,7 +513,7 @@ func (f *FakeFactory) PrintObject(cmd *cobra.Command, isLocal bool, mapper meta.
|
||||
return nil
|
||||
}
|
||||
|
||||
func (f *FakeFactory) PrinterForMapping(printOpts printers.PrintOptions, mapping *meta.RESTMapping) (printers.ResourcePrinter, error) {
|
||||
func (f *FakeFactory) PrinterForMapping(printOpts *printers.PrintOptions, mapping *meta.RESTMapping) (printers.ResourcePrinter, error) {
|
||||
return f.tf.Printer, f.tf.Err
|
||||
}
|
||||
|
||||
@ -744,17 +744,17 @@ func (f *fakeAPIFactory) UnstructuredClientForMapping(m *meta.RESTMapping) (reso
|
||||
return f.tf.UnstructuredClient, f.tf.Err
|
||||
}
|
||||
|
||||
func (f *fakeAPIFactory) PrinterForOptions(options printers.PrintOptions) (printers.ResourcePrinter, error) {
|
||||
func (f *fakeAPIFactory) PrinterForOptions(options *printers.PrintOptions) (printers.ResourcePrinter, error) {
|
||||
return f.tf.Printer, f.tf.Err
|
||||
}
|
||||
|
||||
func (f *fakeAPIFactory) PrintResourceInfoForCommand(cmd *cobra.Command, info *resource.Info, out io.Writer) error {
|
||||
printer, err := f.PrinterForOptions(printers.PrintOptions{})
|
||||
printer, err := f.PrinterForOptions(&printers.PrintOptions{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !printer.IsGeneric() {
|
||||
printer, err = f.PrinterForMapping(printers.PrintOptions{}, nil)
|
||||
printer, err = f.PrinterForMapping(&printers.PrintOptions{}, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -851,14 +851,14 @@ func (f *fakeAPIFactory) PrintObject(cmd *cobra.Command, isLocal bool, mapper me
|
||||
return err
|
||||
}
|
||||
|
||||
printer, err := f.PrinterForMapping(printers.PrintOptions{}, mapping)
|
||||
printer, err := f.PrinterForMapping(&printers.PrintOptions{}, mapping)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return printer.PrintObj(obj, out)
|
||||
}
|
||||
|
||||
func (f *fakeAPIFactory) PrinterForMapping(outputOpts printers.PrintOptions, mapping *meta.RESTMapping) (printers.ResourcePrinter, error) {
|
||||
func (f *fakeAPIFactory) PrinterForMapping(outputOpts *printers.PrintOptions, mapping *meta.RESTMapping) (printers.ResourcePrinter, error) {
|
||||
return f.tf.Printer, f.tf.Err
|
||||
}
|
||||
|
||||
|
@ -230,12 +230,12 @@ type BuilderFactory interface {
|
||||
// PrinterForCommand returns the default printer for the command. It requires that certain options
|
||||
// are declared on the command (see AddPrinterFlags). Returns a printer, or an error if a printer
|
||||
// could not be found.
|
||||
PrinterForOptions(options printers.PrintOptions) (printers.ResourcePrinter, error)
|
||||
PrinterForOptions(options *printers.PrintOptions) (printers.ResourcePrinter, error)
|
||||
// PrinterForMapping returns a printer suitable for displaying the provided resource type.
|
||||
// Requires that printer flags have been added to cmd (see AddPrinterFlags).
|
||||
// Returns a printer, true if the printer is generic (is not internal), or
|
||||
// an error if a printer could not be found.
|
||||
PrinterForMapping(options printers.PrintOptions, mapping *meta.RESTMapping) (printers.ResourcePrinter, error)
|
||||
PrinterForMapping(options *printers.PrintOptions, mapping *meta.RESTMapping) (printers.ResourcePrinter, error)
|
||||
// PrintObject prints an api object given command line flags to modify the output format
|
||||
PrintObject(cmd *cobra.Command, isLocal bool, mapper meta.RESTMapper, obj runtime.Object, out io.Writer) error
|
||||
// PrintResourceInfoForCommand receives a *cobra.Command and a *resource.Info and
|
||||
|
@ -47,7 +47,7 @@ func NewBuilderFactory(clientAccessFactory ClientAccessFactory, objectMappingFac
|
||||
return f
|
||||
}
|
||||
|
||||
func (f *ring2Factory) PrinterForOptions(options printers.PrintOptions) (printers.ResourcePrinter, error) {
|
||||
func (f *ring2Factory) PrinterForOptions(options *printers.PrintOptions) (printers.ResourcePrinter, error) {
|
||||
var mapper meta.RESTMapper
|
||||
var typer runtime.ObjectTyper
|
||||
|
||||
@ -59,7 +59,7 @@ func (f *ring2Factory) PrinterForOptions(options printers.PrintOptions) (printer
|
||||
return PrinterForOptions(mapper, typer, encoder, decoders, options)
|
||||
}
|
||||
|
||||
func (f *ring2Factory) PrinterForMapping(options printers.PrintOptions, mapping *meta.RESTMapping) (printers.ResourcePrinter, error) {
|
||||
func (f *ring2Factory) PrinterForMapping(options *printers.PrintOptions, mapping *meta.RESTMapping) (printers.ResourcePrinter, error) {
|
||||
printer, err := f.PrinterForOptions(options)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -124,7 +124,7 @@ func (f *ring2Factory) PrintObject(cmd *cobra.Command, isLocal bool, mapper meta
|
||||
return err
|
||||
}
|
||||
|
||||
printer, err := f.PrinterForMapping(printers.PrintOptions{}, mapping)
|
||||
printer, err := f.PrinterForMapping(ExtractCmdPrintOptions(cmd, false), mapping)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -132,12 +132,13 @@ func (f *ring2Factory) PrintObject(cmd *cobra.Command, isLocal bool, mapper meta
|
||||
}
|
||||
|
||||
func (f *ring2Factory) PrintResourceInfoForCommand(cmd *cobra.Command, info *resource.Info, out io.Writer) error {
|
||||
printer, err := f.PrinterForOptions(printers.PrintOptions{})
|
||||
printOpts := ExtractCmdPrintOptions(cmd, false)
|
||||
printer, err := f.PrinterForOptions(printOpts)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !printer.IsGeneric() {
|
||||
printer, err = f.PrinterForMapping(printers.PrintOptions{}, nil)
|
||||
printer, err = f.PrinterForMapping(printOpts, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -81,11 +81,11 @@ func ValidateOutputArgs(cmd *cobra.Command) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// printerForOptions returns the printer for the outputOptions (if given) or
|
||||
// PrinterForOptions returns the printer for the outputOptions (if given) or
|
||||
// returns the default printer for the command. Requires that printer flags have
|
||||
// been added to cmd (see AddPrinterFlags).
|
||||
func PrinterForOptions(mapper meta.RESTMapper, typer runtime.ObjectTyper, encoder runtime.Encoder, decoders []runtime.Decoder, options printers.PrintOptions) (printers.ResourcePrinter, error) {
|
||||
printer, err := printers.GetStandardPrinter(mapper, typer, encoder, decoders, options)
|
||||
func PrinterForOptions(mapper meta.RESTMapper, typer runtime.ObjectTyper, encoder runtime.Encoder, decoders []runtime.Decoder, options *printers.PrintOptions) (printers.ResourcePrinter, error) {
|
||||
printer, err := printers.GetStandardPrinter(mapper, typer, encoder, decoders, *options)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -97,7 +97,7 @@ func PrinterForOptions(mapper meta.RESTMapper, typer runtime.ObjectTyper, encode
|
||||
printersinternal.AddHandlers(humanReadablePrinter)
|
||||
}
|
||||
|
||||
return maybeWrapSortingPrinter(printer, options), nil
|
||||
return maybeWrapSortingPrinter(printer, *options), nil
|
||||
}
|
||||
|
||||
// ExtractCmdPrintOptions parses printer specific commandline args and
|
||||
|
Loading…
Reference in New Issue
Block a user