cli-runtime: k8s.io/cli-runtime/pkg/genericclioptions Index | Files

package genericclioptions

import "k8s.io/cli-runtime/pkg/genericclioptions"

Package genericclioptions contains flags which can be added to you command, bound, completed, and produce useful helper functions. Nothing in this package can depend on kube/kube

Index

Package Files

builder_flags.go builder_flags_fake.go config_flags.go config_flags_fake.go doc.go filename_flags.go io_options.go json_yaml_flags.go jsonpath_flags.go kube_template_flags.go name_flags.go print_flags.go record_flags.go template_flags.go

Constants

const ChangeCauseAnnotation = "kubernetes.io/change-cause"

ChangeCauseAnnotation is the annotation indicating a guess at "why" something was changed

func IsNoCompatiblePrinterError Uses

func IsNoCompatiblePrinterError(err error) bool

type ChangeCauseRecorder Uses

type ChangeCauseRecorder struct {
    // contains filtered or unexported fields
}

ChangeCauseRecorder annotates a "change-cause" to an input runtime object

func (*ChangeCauseRecorder) MakeRecordMergePatch Uses

func (r *ChangeCauseRecorder) MakeRecordMergePatch(obj runtime.Object) ([]byte, error)

MakeRecordMergePatch produces a merge patch for updating the recording annotation.

func (*ChangeCauseRecorder) Record Uses

func (r *ChangeCauseRecorder) Record(obj runtime.Object) error

Record annotates a "change-cause" to a given info if either "shouldRecord" is true, or the resource info previously contained a "change-cause" annotation.

type ConfigFlags Uses

type ConfigFlags struct {
    CacheDir   *string
    KubeConfig *string

    // config flags
    ClusterName      *string
    AuthInfoName     *string
    Context          *string
    Namespace        *string
    APIServer        *string
    Insecure         *bool
    CertFile         *string
    KeyFile          *string
    CAFile           *string
    BearerToken      *string
    Impersonate      *string
    ImpersonateGroup *[]string
    Username         *string
    Password         *string
    Timeout          *string
    // contains filtered or unexported fields
}

ConfigFlags composes the set of values necessary for obtaining a REST client config

func NewConfigFlags Uses

func NewConfigFlags(usePersistentConfig bool) *ConfigFlags

NewConfigFlags returns ConfigFlags with default values set

func (*ConfigFlags) AddFlags Uses

func (f *ConfigFlags) AddFlags(flags *pflag.FlagSet)

AddFlags binds client configuration flags to a given flagset

func (*ConfigFlags) ToDiscoveryClient Uses

func (f *ConfigFlags) ToDiscoveryClient() (discovery.CachedDiscoveryInterface, error)

ToDiscoveryClient implements RESTClientGetter. Expects the AddFlags method to have been called. Returns a CachedDiscoveryInterface using a computed RESTConfig.

func (*ConfigFlags) ToRESTConfig Uses

func (f *ConfigFlags) ToRESTConfig() (*rest.Config, error)

ToRESTConfig implements RESTClientGetter. Returns a REST client configuration based on a provided path to a .kubeconfig file, loading rules, and config flag overrides. Expects the AddFlags method to have been called.

func (*ConfigFlags) ToRESTMapper Uses

func (f *ConfigFlags) ToRESTMapper() (meta.RESTMapper, error)

ToRESTMapper returns a mapper.

func (*ConfigFlags) ToRawKubeConfigLoader Uses

func (f *ConfigFlags) ToRawKubeConfigLoader() clientcmd.ClientConfig

ToRawKubeConfigLoader binds config flag values to config overrides Returns an interactive clientConfig if the password flag is enabled, or a non-interactive clientConfig otherwise.

func (*ConfigFlags) WithDeprecatedPasswordFlag Uses

func (f *ConfigFlags) WithDeprecatedPasswordFlag() *ConfigFlags

WithDeprecatedPasswordFlag enables the username and password config flags

type FileNameFlags Uses

type FileNameFlags struct {
    Usage string

    Filenames *[]string
    Kustomize *string
    Recursive *bool
}

Usage of this struct by itself is discouraged. These flags are composed by ResourceBuilderFlags which should be used instead.

func (*FileNameFlags) AddFlags Uses

func (o *FileNameFlags) AddFlags(flags *pflag.FlagSet)

func (*FileNameFlags) ToOptions Uses

func (o *FileNameFlags) ToOptions() resource.FilenameOptions

type GoTemplatePrintFlags Uses

type GoTemplatePrintFlags struct {
    // indicates if it is OK to ignore missing keys for rendering
    // an output template.
    AllowMissingKeys *bool
    TemplateArgument *string
}

GoTemplatePrintFlags provides default flags necessary for template printing. Given the following flag values, a printer can be requested that knows how to handle printing based on these values.

func NewGoTemplatePrintFlags Uses

func NewGoTemplatePrintFlags() *GoTemplatePrintFlags

NewGoTemplatePrintFlags returns flags associated with --template printing, with default values set.

func (*GoTemplatePrintFlags) AddFlags Uses

func (f *GoTemplatePrintFlags) AddFlags(c *cobra.Command)

AddFlags receives a *cobra.Command reference and binds flags related to template printing to it

func (*GoTemplatePrintFlags) AllowedFormats Uses

func (f *GoTemplatePrintFlags) AllowedFormats() []string

func (*GoTemplatePrintFlags) ToPrinter Uses

func (f *GoTemplatePrintFlags) ToPrinter(templateFormat string) (printers.ResourcePrinter, error)

ToPrinter receives an templateFormat and returns a printer capable of handling --template format printing. Returns false if the specified templateFormat does not match a template format.

type IOStreams Uses

type IOStreams struct {
    // In think, os.Stdin
    In  io.Reader
    // Out think, os.Stdout
    Out io.Writer
    // ErrOut think, os.Stderr
    ErrOut io.Writer
}

IOStreams provides the standard names for iostreams. This is useful for embedding and for unit testing. Inconsistent and different names make it hard to read and review code

func NewTestIOStreams Uses

func NewTestIOStreams() (IOStreams, *bytes.Buffer, *bytes.Buffer, *bytes.Buffer)

NewTestIOStreams returns a valid IOStreams and in, out, errout buffers for unit tests

func NewTestIOStreamsDiscard Uses

func NewTestIOStreamsDiscard() IOStreams

NewTestIOStreamsDiscard returns a valid IOStreams that just discards

type JSONPathPrintFlags Uses

type JSONPathPrintFlags struct {
    // indicates if it is OK to ignore missing keys for rendering
    // an output template.
    AllowMissingKeys *bool
    TemplateArgument *string
}

JSONPathPrintFlags provides default flags necessary for template printing. Given the following flag values, a printer can be requested that knows how to handle printing based on these values.

func NewJSONPathPrintFlags Uses

func NewJSONPathPrintFlags(templateValue string, allowMissingKeys bool) *JSONPathPrintFlags

NewJSONPathPrintFlags returns flags associated with --template printing, with default values set.

func (*JSONPathPrintFlags) AddFlags Uses

func (f *JSONPathPrintFlags) AddFlags(c *cobra.Command)

AddFlags receives a *cobra.Command reference and binds flags related to template printing to it

func (*JSONPathPrintFlags) AllowedFormats Uses

func (f *JSONPathPrintFlags) AllowedFormats() []string

func (*JSONPathPrintFlags) ToPrinter Uses

func (f *JSONPathPrintFlags) ToPrinter(templateFormat string) (printers.ResourcePrinter, error)

ToPrinter receives an templateFormat and returns a printer capable of handling --template format printing. Returns false if the specified templateFormat does not match a template format.

type JSONYamlPrintFlags Uses

type JSONYamlPrintFlags struct {
}

JSONYamlPrintFlags provides default flags necessary for json/yaml printing. Given the following flag values, a printer can be requested that knows how to handle printing based on these values.

func NewJSONYamlPrintFlags Uses

func NewJSONYamlPrintFlags() *JSONYamlPrintFlags

NewJSONYamlPrintFlags returns flags associated with yaml or json printing, with default values set.

func (*JSONYamlPrintFlags) AddFlags Uses

func (f *JSONYamlPrintFlags) AddFlags(c *cobra.Command)

AddFlags receives a *cobra.Command reference and binds flags related to JSON or Yaml printing to it

func (*JSONYamlPrintFlags) AllowedFormats Uses

func (f *JSONYamlPrintFlags) AllowedFormats() []string

func (*JSONYamlPrintFlags) ToPrinter Uses

func (f *JSONYamlPrintFlags) ToPrinter(outputFormat string) (printers.ResourcePrinter, error)

ToPrinter receives an outputFormat and returns a printer capable of handling --output=(yaml|json) printing. Returns false if the specified outputFormat does not match a supported format. Supported Format types can be found in pkg/printers/printers.go

type KubeTemplatePrintFlags Uses

type KubeTemplatePrintFlags struct {
    GoTemplatePrintFlags *GoTemplatePrintFlags
    JSONPathPrintFlags   *JSONPathPrintFlags

    AllowMissingKeys *bool
    TemplateArgument *string
}

KubeTemplatePrintFlags composes print flags that provide both a JSONPath and a go-template printer. This is necessary if dealing with cases that require support both both printers, since both sets of flags require overlapping flags.

func NewKubeTemplatePrintFlags Uses

func NewKubeTemplatePrintFlags() *KubeTemplatePrintFlags

NewKubeTemplatePrintFlags returns flags associated with --template printing, with default values set.

func (*KubeTemplatePrintFlags) AddFlags Uses

func (f *KubeTemplatePrintFlags) AddFlags(c *cobra.Command)

AddFlags receives a *cobra.Command reference and binds flags related to template printing to it

func (*KubeTemplatePrintFlags) AllowedFormats Uses

func (f *KubeTemplatePrintFlags) AllowedFormats() []string

func (*KubeTemplatePrintFlags) ToPrinter Uses

func (f *KubeTemplatePrintFlags) ToPrinter(outputFormat string) (printers.ResourcePrinter, error)

type NamePrintFlags Uses

type NamePrintFlags struct {
    // Operation describes the name of the action that
    // took place on an object, to be included in the
    // finalized "successful" message.
    Operation string
}

NamePrintFlags provides default flags necessary for printing a resource's fully-qualified Kind.group/name, or a successful message about that resource if an Operation is provided.

func NewNamePrintFlags Uses

func NewNamePrintFlags(operation string) *NamePrintFlags

NewNamePrintFlags returns flags associated with --name printing, with default values set.

func (*NamePrintFlags) AddFlags Uses

func (f *NamePrintFlags) AddFlags(c *cobra.Command)

AddFlags receives a *cobra.Command reference and binds flags related to name printing to it

func (*NamePrintFlags) AllowedFormats Uses

func (f *NamePrintFlags) AllowedFormats() []string

func (*NamePrintFlags) Complete Uses

func (f *NamePrintFlags) Complete(successTemplate string) error

func (*NamePrintFlags) ToPrinter Uses

func (f *NamePrintFlags) ToPrinter(outputFormat string) (printers.ResourcePrinter, error)

ToPrinter receives an outputFormat and returns a printer capable of handling --output=name printing. Returns false if the specified outputFormat does not match a supported format. Supported format types can be found in pkg/printers/printers.go

type NoCompatiblePrinterError Uses

type NoCompatiblePrinterError struct {
    OutputFormat   *string
    AllowedFormats []string
    Options        interface{}
}

func (NoCompatiblePrinterError) Error Uses

func (e NoCompatiblePrinterError) Error() string

type NoopRecorder Uses

type NoopRecorder struct{}

NoopRecorder does nothing. It is a "do nothing" that can be returned so code doesn't switch on it.

func (NoopRecorder) MakeRecordMergePatch Uses

func (r NoopRecorder) MakeRecordMergePatch(obj runtime.Object) ([]byte, error)

MakeRecordMergePatch implements Recorder

func (NoopRecorder) Record Uses

func (r NoopRecorder) Record(obj runtime.Object) error

Record implements Recorder

type PrintFlags Uses

type PrintFlags struct {
    JSONYamlPrintFlags   *JSONYamlPrintFlags
    NamePrintFlags       *NamePrintFlags
    TemplatePrinterFlags *KubeTemplatePrintFlags

    TypeSetterPrinter *printers.TypeSetterPrinter

    OutputFormat *string

    // OutputFlagSpecified indicates whether the user specifically requested a certain kind of output.
    // Using this function allows a sophisticated caller to change the flag binding logic if they so desire.
    OutputFlagSpecified func() bool
}

PrintFlags composes common printer flag structs used across all commands, and provides a method of retrieving a known printer based on flag values provided.

func NewPrintFlags Uses

func NewPrintFlags(operation string) *PrintFlags

func (*PrintFlags) AddFlags Uses

func (f *PrintFlags) AddFlags(cmd *cobra.Command)

func (*PrintFlags) AllowedFormats Uses

func (f *PrintFlags) AllowedFormats() []string

func (*PrintFlags) Complete Uses

func (f *PrintFlags) Complete(successTemplate string) error

func (*PrintFlags) ToPrinter Uses

func (f *PrintFlags) ToPrinter() (printers.ResourcePrinter, error)

func (*PrintFlags) WithDefaultOutput Uses

func (f *PrintFlags) WithDefaultOutput(output string) *PrintFlags

WithDefaultOutput sets a default output format if one is not provided through a flag value

func (*PrintFlags) WithTypeSetter Uses

func (f *PrintFlags) WithTypeSetter(scheme *runtime.Scheme) *PrintFlags

WithTypeSetter sets a wrapper than will surround the returned printer with a printer to type resources

type RESTClientGetter Uses

type RESTClientGetter interface {
    // ToRESTConfig returns restconfig
    ToRESTConfig() (*rest.Config, error)
    // ToDiscoveryClient returns discovery client
    ToDiscoveryClient() (discovery.CachedDiscoveryInterface, error)
    // ToRESTMapper returns a restmapper
    ToRESTMapper() (meta.RESTMapper, error)
    // ToRawKubeConfigLoader return kubeconfig loader as-is
    ToRawKubeConfigLoader() clientcmd.ClientConfig
}

RESTClientGetter is an interface that the ConfigFlags describe to provide an easier way to mock for commands and eliminate the direct coupling to a struct type. Users may wish to duplicate this type in their own packages as per the golang type overlapping.

type RecordFlags Uses

type RecordFlags struct {
    // Record indicates the state of the recording flag.  It is a pointer so a caller can opt out or rebind
    Record *bool
    // contains filtered or unexported fields
}

RecordFlags contains all flags associated with the "--record" operation

func NewRecordFlags Uses

func NewRecordFlags() *RecordFlags

NewRecordFlags provides a RecordFlags with reasonable default values set for use

func (*RecordFlags) AddFlags Uses

func (f *RecordFlags) AddFlags(cmd *cobra.Command)

AddFlags binds the requested flags to the provided flagset TODO have this only take a flagset

func (*RecordFlags) Complete Uses

func (f *RecordFlags) Complete(cmd *cobra.Command) error

Complete is called before the command is run, but after it is invoked to finish the state of the struct before use.

func (*RecordFlags) CompleteWithChangeCause Uses

func (f *RecordFlags) CompleteWithChangeCause(cause string) error

func (*RecordFlags) ToRecorder Uses

func (f *RecordFlags) ToRecorder() (Recorder, error)

ToRecorder returns a ChangeCause recorder if --record=false was not explicitly given by the user

type Recorder Uses

type Recorder interface {
    // Record records why a runtime.Object was changed in an annotation.
    Record(runtime.Object) error
    MakeRecordMergePatch(runtime.Object) ([]byte, error)
}

Recorder is used to record why a runtime.Object was changed in an annotation.

type ResourceBuilderFlags Uses

type ResourceBuilderFlags struct {
    FileNameFlags *FileNameFlags

    LabelSelector *string
    FieldSelector *string
    AllNamespaces *bool
    All           *bool
    Local         *bool

    Scheme           *runtime.Scheme
    Latest           bool
    StopOnFirstError bool
}

ResourceBuilderFlags are flags for finding resources TODO(juanvallejo): wire --local flag from commands through

func NewResourceBuilderFlags Uses

func NewResourceBuilderFlags() *ResourceBuilderFlags

NewResourceBuilderFlags returns a default ResourceBuilderFlags

func (*ResourceBuilderFlags) AddFlags Uses

func (o *ResourceBuilderFlags) AddFlags(flagset *pflag.FlagSet)

AddFlags registers flags for finding resources

func (*ResourceBuilderFlags) StopOnError Uses

func (o *ResourceBuilderFlags) StopOnError() *ResourceBuilderFlags

func (*ResourceBuilderFlags) ToBuilder Uses

func (o *ResourceBuilderFlags) ToBuilder(restClientGetter RESTClientGetter, resources []string) ResourceFinder

ToBuilder gives you back a resource finder to visit resources that are located

func (*ResourceBuilderFlags) WithAll Uses

func (o *ResourceBuilderFlags) WithAll(defaultVal bool) *ResourceBuilderFlags

func (*ResourceBuilderFlags) WithAllNamespaces Uses

func (o *ResourceBuilderFlags) WithAllNamespaces(defaultVal bool) *ResourceBuilderFlags

func (*ResourceBuilderFlags) WithFieldSelector Uses

func (o *ResourceBuilderFlags) WithFieldSelector(selector string) *ResourceBuilderFlags

func (*ResourceBuilderFlags) WithFile Uses

func (o *ResourceBuilderFlags) WithFile(recurse bool, files ...string) *ResourceBuilderFlags

func (*ResourceBuilderFlags) WithLabelSelector Uses

func (o *ResourceBuilderFlags) WithLabelSelector(selector string) *ResourceBuilderFlags

func (*ResourceBuilderFlags) WithLatest Uses

func (o *ResourceBuilderFlags) WithLatest() *ResourceBuilderFlags

func (*ResourceBuilderFlags) WithLocal Uses

func (o *ResourceBuilderFlags) WithLocal(defaultVal bool) *ResourceBuilderFlags

func (*ResourceBuilderFlags) WithScheme Uses

func (o *ResourceBuilderFlags) WithScheme(scheme *runtime.Scheme) *ResourceBuilderFlags

type ResourceFindBuilderWrapper Uses

type ResourceFindBuilderWrapper struct {
    // contains filtered or unexported fields
}

ResourceFindBuilderWrapper wraps a builder in an interface

func (*ResourceFindBuilderWrapper) Do Uses

func (b *ResourceFindBuilderWrapper) Do() resource.Visitor

Do finds you resources to check

type ResourceFinder Uses

type ResourceFinder interface {
    Do() resource.Visitor
}

ResourceFinder allows mocking the resource builder TODO resource builders needs to become more interfacey

func NewSimpleFakeResourceFinder Uses

func NewSimpleFakeResourceFinder(infos ...*resource.Info) ResourceFinder

NewSimpleResourceFinder builds a super simple ResourceFinder that just iterates over the objects you provided

func ResourceFinderForResult Uses

func ResourceFinderForResult(result resource.Visitor) ResourceFinder

ResourceFinderForResult skins a visitor for re-use as a ResourceFinder

type ResourceFinderFunc Uses

type ResourceFinderFunc func() resource.Visitor

ResourceFinderFunc is a handy way to make a ResourceFinder

func (ResourceFinderFunc) Do Uses

func (fn ResourceFinderFunc) Do() resource.Visitor

Do implements ResourceFinder

type TestConfigFlags Uses

type TestConfigFlags struct {
    // contains filtered or unexported fields
}

func NewTestConfigFlags Uses

func NewTestConfigFlags() *TestConfigFlags

func (*TestConfigFlags) ToDiscoveryClient Uses

func (f *TestConfigFlags) ToDiscoveryClient() (discovery.CachedDiscoveryInterface, error)

func (*TestConfigFlags) ToRESTConfig Uses

func (f *TestConfigFlags) ToRESTConfig() (*rest.Config, error)

func (*TestConfigFlags) ToRESTMapper Uses

func (f *TestConfigFlags) ToRESTMapper() (meta.RESTMapper, error)

func (*TestConfigFlags) ToRawKubeConfigLoader Uses

func (f *TestConfigFlags) ToRawKubeConfigLoader() clientcmd.ClientConfig

func (*TestConfigFlags) WithClientConfig Uses

func (f *TestConfigFlags) WithClientConfig(clientConfig clientcmd.ClientConfig) *TestConfigFlags

func (*TestConfigFlags) WithDiscoveryClient Uses

func (f *TestConfigFlags) WithDiscoveryClient(c discovery.CachedDiscoveryInterface) *TestConfigFlags

func (*TestConfigFlags) WithNamespace Uses

func (f *TestConfigFlags) WithNamespace(ns string) *TestConfigFlags

func (*TestConfigFlags) WithRESTMapper Uses

func (f *TestConfigFlags) WithRESTMapper(mapper meta.RESTMapper) *TestConfigFlags

Package genericclioptions imports 26 packages (graph) and is imported by 382 packages. Updated 2019-11-02. Refresh now. Tools for package owners.