13
vendor/k8s.io/cli-runtime/pkg/genericclioptions/json_yaml_flags.go
generated
vendored
13
vendor/k8s.io/cli-runtime/pkg/genericclioptions/json_yaml_flags.go
generated
vendored
@@ -24,6 +24,7 @@ import (
|
||||
"k8s.io/cli-runtime/pkg/printers"
|
||||
)
|
||||
|
||||
// AllowedFormats returns slice of string of allowed JSONYaml printing format
|
||||
func (f *JSONYamlPrintFlags) AllowedFormats() []string {
|
||||
if f == nil {
|
||||
return []string{}
|
||||
@@ -35,6 +36,7 @@ func (f *JSONYamlPrintFlags) AllowedFormats() []string {
|
||||
// Given the following flag values, a printer can be requested that knows
|
||||
// how to handle printing based on these values.
|
||||
type JSONYamlPrintFlags struct {
|
||||
showManagedFields bool
|
||||
}
|
||||
|
||||
// ToPrinter receives an outputFormat and returns a printer capable of
|
||||
@@ -54,12 +56,21 @@ func (f *JSONYamlPrintFlags) ToPrinter(outputFormat string) (printers.ResourcePr
|
||||
return nil, NoCompatiblePrinterError{OutputFormat: &outputFormat, AllowedFormats: f.AllowedFormats()}
|
||||
}
|
||||
|
||||
if !f.showManagedFields {
|
||||
printer = &printers.OmitManagedFieldsPrinter{Delegate: printer}
|
||||
}
|
||||
return printer, nil
|
||||
}
|
||||
|
||||
// AddFlags receives a *cobra.Command reference and binds
|
||||
// flags related to JSON or Yaml printing to it
|
||||
func (f *JSONYamlPrintFlags) AddFlags(c *cobra.Command) {}
|
||||
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.")
|
||||
}
|
||||
|
||||
// NewJSONYamlPrintFlags returns flags associated with
|
||||
// yaml or json printing, with default values set.
|
||||
|
||||
Reference in New Issue
Block a user