From 81d9606554288cdb2a1c86ee3b2ff6aaded72df9 Mon Sep 17 00:00:00 2001 From: Maciej Szulik Date: Tue, 23 Mar 2021 20:42:35 +0100 Subject: [PATCH] Prevent nil-pointer exception when constructing PrinterFlags --- .../cli-runtime/pkg/genericclioptions/json_yaml_flags.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/staging/src/k8s.io/cli-runtime/pkg/genericclioptions/json_yaml_flags.go b/staging/src/k8s.io/cli-runtime/pkg/genericclioptions/json_yaml_flags.go index cd1d039f853..0f2bdcdaf03 100644 --- a/staging/src/k8s.io/cli-runtime/pkg/genericclioptions/json_yaml_flags.go +++ b/staging/src/k8s.io/cli-runtime/pkg/genericclioptions/json_yaml_flags.go @@ -65,6 +65,10 @@ func (f *JSONYamlPrintFlags) ToPrinter(outputFormat string) (printers.ResourcePr // AddFlags receives a *cobra.Command reference and binds // flags related to JSON or Yaml printing to it func (f *JSONYamlPrintFlags) AddFlags(c *cobra.Command) { + if f == nil { + return + } + c.Flags().BoolVar(&f.showManagedFields, "show-managed-fields", f.showManagedFields, "If true, keep the managedFields when printing objects in JSON or YAML format.") }