mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-26 05:03:09 +00:00
Merge pull request #98003 from lauchokyip/fixlint2
Fix golint errors for k8s.io/cli-runtime/pkg/genericclioptions/
This commit is contained in:
commit
7eef3ed8c7
@ -343,7 +343,6 @@ staging/src/k8s.io/apiserver/plugin/pkg/authenticator/token/oidc
|
|||||||
staging/src/k8s.io/apiserver/plugin/pkg/authenticator/token/tokentest
|
staging/src/k8s.io/apiserver/plugin/pkg/authenticator/token/tokentest
|
||||||
staging/src/k8s.io/apiserver/plugin/pkg/authenticator/token/webhook
|
staging/src/k8s.io/apiserver/plugin/pkg/authenticator/token/webhook
|
||||||
staging/src/k8s.io/apiserver/plugin/pkg/authorizer/webhook
|
staging/src/k8s.io/apiserver/plugin/pkg/authorizer/webhook
|
||||||
staging/src/k8s.io/cli-runtime/pkg/genericclioptions
|
|
||||||
staging/src/k8s.io/cli-runtime/pkg/printers
|
staging/src/k8s.io/cli-runtime/pkg/printers
|
||||||
staging/src/k8s.io/cli-runtime/pkg/resource
|
staging/src/k8s.io/cli-runtime/pkg/resource
|
||||||
staging/src/k8s.io/client-go/discovery
|
staging/src/k8s.io/client-go/discovery
|
||||||
|
@ -52,6 +52,9 @@ func NewResourceBuilderFlags() *ResourceBuilderFlags {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WithFile sets the FileNameFlags.
|
||||||
|
// If recurse is set, it will process directory recursively. Useful when you want to manage related manifests
|
||||||
|
// organized within the same directory.
|
||||||
func (o *ResourceBuilderFlags) WithFile(recurse bool, files ...string) *ResourceBuilderFlags {
|
func (o *ResourceBuilderFlags) WithFile(recurse bool, files ...string) *ResourceBuilderFlags {
|
||||||
o.FileNameFlags = &FileNameFlags{
|
o.FileNameFlags = &FileNameFlags{
|
||||||
Usage: "identifying the resource.",
|
Usage: "identifying the resource.",
|
||||||
@ -62,41 +65,49 @@ func (o *ResourceBuilderFlags) WithFile(recurse bool, files ...string) *Resource
|
|||||||
return o
|
return o
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WithLabelSelector sets the LabelSelector flag
|
||||||
func (o *ResourceBuilderFlags) WithLabelSelector(selector string) *ResourceBuilderFlags {
|
func (o *ResourceBuilderFlags) WithLabelSelector(selector string) *ResourceBuilderFlags {
|
||||||
o.LabelSelector = &selector
|
o.LabelSelector = &selector
|
||||||
return o
|
return o
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WithFieldSelector sets the FieldSelector flag
|
||||||
func (o *ResourceBuilderFlags) WithFieldSelector(selector string) *ResourceBuilderFlags {
|
func (o *ResourceBuilderFlags) WithFieldSelector(selector string) *ResourceBuilderFlags {
|
||||||
o.FieldSelector = &selector
|
o.FieldSelector = &selector
|
||||||
return o
|
return o
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WithAllNamespaces sets the AllNamespaces flag
|
||||||
func (o *ResourceBuilderFlags) WithAllNamespaces(defaultVal bool) *ResourceBuilderFlags {
|
func (o *ResourceBuilderFlags) WithAllNamespaces(defaultVal bool) *ResourceBuilderFlags {
|
||||||
o.AllNamespaces = &defaultVal
|
o.AllNamespaces = &defaultVal
|
||||||
return o
|
return o
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WithAll sets the All flag
|
||||||
func (o *ResourceBuilderFlags) WithAll(defaultVal bool) *ResourceBuilderFlags {
|
func (o *ResourceBuilderFlags) WithAll(defaultVal bool) *ResourceBuilderFlags {
|
||||||
o.All = &defaultVal
|
o.All = &defaultVal
|
||||||
return o
|
return o
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WithLocal sets the Local flag
|
||||||
func (o *ResourceBuilderFlags) WithLocal(defaultVal bool) *ResourceBuilderFlags {
|
func (o *ResourceBuilderFlags) WithLocal(defaultVal bool) *ResourceBuilderFlags {
|
||||||
o.Local = &defaultVal
|
o.Local = &defaultVal
|
||||||
return o
|
return o
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WithScheme sets the Scheme flag
|
||||||
func (o *ResourceBuilderFlags) WithScheme(scheme *runtime.Scheme) *ResourceBuilderFlags {
|
func (o *ResourceBuilderFlags) WithScheme(scheme *runtime.Scheme) *ResourceBuilderFlags {
|
||||||
o.Scheme = scheme
|
o.Scheme = scheme
|
||||||
return o
|
return o
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WithLatest sets the Latest flag
|
||||||
func (o *ResourceBuilderFlags) WithLatest() *ResourceBuilderFlags {
|
func (o *ResourceBuilderFlags) WithLatest() *ResourceBuilderFlags {
|
||||||
o.Latest = true
|
o.Latest = true
|
||||||
return o
|
return o
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// StopOnError sets the StopOnFirstError flag
|
||||||
func (o *ResourceBuilderFlags) StopOnError() *ResourceBuilderFlags {
|
func (o *ResourceBuilderFlags) StopOnError() *ResourceBuilderFlags {
|
||||||
o.StopOnFirstError = true
|
o.StopOnFirstError = true
|
||||||
return o
|
return o
|
||||||
|
@ -20,7 +20,7 @@ import (
|
|||||||
"k8s.io/cli-runtime/pkg/resource"
|
"k8s.io/cli-runtime/pkg/resource"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewSimpleResourceFinder builds a super simple ResourceFinder that just iterates over the objects you provided
|
// NewSimpleFakeResourceFinder builds a super simple ResourceFinder that just iterates over the objects you provided
|
||||||
func NewSimpleFakeResourceFinder(infos ...*resource.Info) ResourceFinder {
|
func NewSimpleFakeResourceFinder(infos ...*resource.Info) ResourceFinder {
|
||||||
return &fakeResourceFinder{
|
return &fakeResourceFinder{
|
||||||
Infos: infos,
|
Infos: infos,
|
||||||
|
@ -23,6 +23,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
// ErrEmptyConfig is the error message to be displayed if the configuration info is missing or incomplete
|
||||||
ErrEmptyConfig = clientcmd.NewEmptyConfigError(`Missing or incomplete configuration info. Please point to an existing, complete config file:
|
ErrEmptyConfig = clientcmd.NewEmptyConfigError(`Missing or incomplete configuration info. Please point to an existing, complete config file:
|
||||||
|
|
||||||
|
|
||||||
|
@ -27,12 +27,16 @@ import (
|
|||||||
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
|
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// TestConfigFlags contains clientConfig struct
|
||||||
|
// and interfaces that implements RESTClientGetter
|
||||||
type TestConfigFlags struct {
|
type TestConfigFlags struct {
|
||||||
clientConfig clientcmd.ClientConfig
|
clientConfig clientcmd.ClientConfig
|
||||||
discoveryClient discovery.CachedDiscoveryInterface
|
discoveryClient discovery.CachedDiscoveryInterface
|
||||||
restMapper meta.RESTMapper
|
restMapper meta.RESTMapper
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ToRawKubeConfigLoader implements RESTClientGetter
|
||||||
|
// Returns a clientconfig if it's set
|
||||||
func (f *TestConfigFlags) ToRawKubeConfigLoader() clientcmd.ClientConfig {
|
func (f *TestConfigFlags) ToRawKubeConfigLoader() clientcmd.ClientConfig {
|
||||||
if f.clientConfig == nil {
|
if f.clientConfig == nil {
|
||||||
panic("attempt to obtain a test RawKubeConfigLoader with no clientConfig specified")
|
panic("attempt to obtain a test RawKubeConfigLoader with no clientConfig specified")
|
||||||
@ -40,14 +44,22 @@ func (f *TestConfigFlags) ToRawKubeConfigLoader() clientcmd.ClientConfig {
|
|||||||
return f.clientConfig
|
return f.clientConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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 (f *TestConfigFlags) ToRESTConfig() (*rest.Config, error) {
|
func (f *TestConfigFlags) ToRESTConfig() (*rest.Config, error) {
|
||||||
return f.ToRawKubeConfigLoader().ClientConfig()
|
return f.ToRawKubeConfigLoader().ClientConfig()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ToDiscoveryClient implements RESTClientGetter.
|
||||||
|
// Returns a CachedDiscoveryInterface
|
||||||
func (f *TestConfigFlags) ToDiscoveryClient() (discovery.CachedDiscoveryInterface, error) {
|
func (f *TestConfigFlags) ToDiscoveryClient() (discovery.CachedDiscoveryInterface, error) {
|
||||||
return f.discoveryClient, nil
|
return f.discoveryClient, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ToRESTMapper implements RESTClientGetter.
|
||||||
|
// Returns a mapper.
|
||||||
func (f *TestConfigFlags) ToRESTMapper() (meta.RESTMapper, error) {
|
func (f *TestConfigFlags) ToRESTMapper() (meta.RESTMapper, error) {
|
||||||
if f.restMapper != nil {
|
if f.restMapper != nil {
|
||||||
return f.restMapper, nil
|
return f.restMapper, nil
|
||||||
@ -60,21 +72,25 @@ func (f *TestConfigFlags) ToRESTMapper() (meta.RESTMapper, error) {
|
|||||||
return nil, fmt.Errorf("no restmapper")
|
return nil, fmt.Errorf("no restmapper")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WithClientConfig sets the clientConfig flag
|
||||||
func (f *TestConfigFlags) WithClientConfig(clientConfig clientcmd.ClientConfig) *TestConfigFlags {
|
func (f *TestConfigFlags) WithClientConfig(clientConfig clientcmd.ClientConfig) *TestConfigFlags {
|
||||||
f.clientConfig = clientConfig
|
f.clientConfig = clientConfig
|
||||||
return f
|
return f
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WithRESTMapper sets the restMapper flag
|
||||||
func (f *TestConfigFlags) WithRESTMapper(mapper meta.RESTMapper) *TestConfigFlags {
|
func (f *TestConfigFlags) WithRESTMapper(mapper meta.RESTMapper) *TestConfigFlags {
|
||||||
f.restMapper = mapper
|
f.restMapper = mapper
|
||||||
return f
|
return f
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WithDiscoveryClient sets the discoveryClient flag
|
||||||
func (f *TestConfigFlags) WithDiscoveryClient(c discovery.CachedDiscoveryInterface) *TestConfigFlags {
|
func (f *TestConfigFlags) WithDiscoveryClient(c discovery.CachedDiscoveryInterface) *TestConfigFlags {
|
||||||
f.discoveryClient = c
|
f.discoveryClient = c
|
||||||
return f
|
return f
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WithNamespace sets the clientConfig flag by modifying delagate and namespace
|
||||||
func (f *TestConfigFlags) WithNamespace(ns string) *TestConfigFlags {
|
func (f *TestConfigFlags) WithNamespace(ns string) *TestConfigFlags {
|
||||||
if f.clientConfig == nil {
|
if f.clientConfig == nil {
|
||||||
panic("attempt to obtain a test RawKubeConfigLoader with no clientConfig specified")
|
panic("attempt to obtain a test RawKubeConfigLoader with no clientConfig specified")
|
||||||
@ -86,6 +102,7 @@ func (f *TestConfigFlags) WithNamespace(ns string) *TestConfigFlags {
|
|||||||
return f
|
return f
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewTestConfigFlags builds a TestConfigFlags struct to test ConfigFlags
|
||||||
func NewTestConfigFlags() *TestConfigFlags {
|
func NewTestConfigFlags() *TestConfigFlags {
|
||||||
return &TestConfigFlags{}
|
return &TestConfigFlags{}
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,6 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Package genericclioptions contains flags which can be added to you command, bound, completed, and produce
|
// Package genericclioptions contains flags which can be added to your command, bound, completed, and produce
|
||||||
// useful helper functions. Nothing in this package can depend on kube/kube
|
// useful helper functions. Nothing in this package can depend on kube/kube
|
||||||
package genericclioptions // import "k8s.io/cli-runtime/pkg/genericclioptions"
|
package genericclioptions // import "k8s.io/cli-runtime/pkg/genericclioptions"
|
||||||
|
@ -25,6 +25,7 @@ import (
|
|||||||
"k8s.io/cli-runtime/pkg/resource"
|
"k8s.io/cli-runtime/pkg/resource"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// FileNameFlags are flags for processing files.
|
||||||
// Usage of this struct by itself is discouraged.
|
// Usage of this struct by itself is discouraged.
|
||||||
// These flags are composed by ResourceBuilderFlags
|
// These flags are composed by ResourceBuilderFlags
|
||||||
// which should be used instead.
|
// which should be used instead.
|
||||||
@ -36,6 +37,7 @@ type FileNameFlags struct {
|
|||||||
Recursive *bool
|
Recursive *bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ToOptions creates a new FileNameOptions struct and sets FilenameOptions based on FileNameflags
|
||||||
func (o *FileNameFlags) ToOptions() resource.FilenameOptions {
|
func (o *FileNameFlags) ToOptions() resource.FilenameOptions {
|
||||||
options := resource.FilenameOptions{}
|
options := resource.FilenameOptions{}
|
||||||
|
|
||||||
@ -56,6 +58,7 @@ func (o *FileNameFlags) ToOptions() resource.FilenameOptions {
|
|||||||
return options
|
return options
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AddFlags binds file name flags to a given flagset
|
||||||
func (o *FileNameFlags) AddFlags(flags *pflag.FlagSet) {
|
func (o *FileNameFlags) AddFlags(flags *pflag.FlagSet) {
|
||||||
if o == nil {
|
if o == nil {
|
||||||
return
|
return
|
||||||
|
@ -24,6 +24,7 @@ import (
|
|||||||
"k8s.io/cli-runtime/pkg/printers"
|
"k8s.io/cli-runtime/pkg/printers"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// AllowedFormats returns slice of string of allowed JSONYaml printing format
|
||||||
func (f *JSONYamlPrintFlags) AllowedFormats() []string {
|
func (f *JSONYamlPrintFlags) AllowedFormats() []string {
|
||||||
if f == nil {
|
if f == nil {
|
||||||
return []string{}
|
return []string{}
|
||||||
|
@ -46,6 +46,7 @@ type JSONPathPrintFlags struct {
|
|||||||
TemplateArgument *string
|
TemplateArgument *string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AllowedFormats returns slice of string of allowed JSONPath printing format
|
||||||
func (f *JSONPathPrintFlags) AllowedFormats() []string {
|
func (f *JSONPathPrintFlags) AllowedFormats() []string {
|
||||||
formats := make([]string, 0, len(jsonFormats))
|
formats := make([]string, 0, len(jsonFormats))
|
||||||
for format := range jsonFormats {
|
for format := range jsonFormats {
|
||||||
@ -89,7 +90,7 @@ func (f *JSONPathPrintFlags) ToPrinter(templateFormat string) (printers.Resource
|
|||||||
if templateFormat == "jsonpath-file" {
|
if templateFormat == "jsonpath-file" {
|
||||||
data, err := ioutil.ReadFile(templateValue)
|
data, err := ioutil.ReadFile(templateValue)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("error reading --template %s, %v\n", templateValue, err)
|
return nil, fmt.Errorf("error reading --template %s, %v", templateValue, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
templateValue = string(data)
|
templateValue = string(data)
|
||||||
@ -97,7 +98,7 @@ func (f *JSONPathPrintFlags) ToPrinter(templateFormat string) (printers.Resource
|
|||||||
|
|
||||||
p, err := printers.NewJSONPathPrinter(templateValue)
|
p, err := printers.NewJSONPathPrinter(templateValue)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("error parsing jsonpath %s, %v\n", templateValue, err)
|
return nil, fmt.Errorf("error parsing jsonpath %s, %v", templateValue, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
allowMissingKeys := true
|
allowMissingKeys := true
|
||||||
|
@ -33,6 +33,7 @@ type KubeTemplatePrintFlags struct {
|
|||||||
TemplateArgument *string
|
TemplateArgument *string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AllowedFormats returns slice of string of allowed GoTemplete and JSONPathPrint printing formats
|
||||||
func (f *KubeTemplatePrintFlags) AllowedFormats() []string {
|
func (f *KubeTemplatePrintFlags) AllowedFormats() []string {
|
||||||
if f == nil {
|
if f == nil {
|
||||||
return []string{}
|
return []string{}
|
||||||
@ -40,6 +41,10 @@ func (f *KubeTemplatePrintFlags) AllowedFormats() []string {
|
|||||||
return append(f.GoTemplatePrintFlags.AllowedFormats(), f.JSONPathPrintFlags.AllowedFormats()...)
|
return append(f.GoTemplatePrintFlags.AllowedFormats(), f.JSONPathPrintFlags.AllowedFormats()...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ToPrinter receives an outputFormat and returns a printer capable of
|
||||||
|
// handling --template printing.
|
||||||
|
// Returns false if the specified outputFormat does not match a supported format.
|
||||||
|
// Supported Format types can be found in pkg/printers/printers.go
|
||||||
func (f *KubeTemplatePrintFlags) ToPrinter(outputFormat string) (printers.ResourcePrinter, error) {
|
func (f *KubeTemplatePrintFlags) ToPrinter(outputFormat string) (printers.ResourcePrinter, error) {
|
||||||
if f == nil {
|
if f == nil {
|
||||||
return nil, NoCompatiblePrinterError{}
|
return nil, NoCompatiblePrinterError{}
|
||||||
|
@ -35,11 +35,13 @@ type NamePrintFlags struct {
|
|||||||
Operation string
|
Operation string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Complete sets NamePrintFlags operation flag from sucessTemplate
|
||||||
func (f *NamePrintFlags) Complete(successTemplate string) error {
|
func (f *NamePrintFlags) Complete(successTemplate string) error {
|
||||||
f.Operation = fmt.Sprintf(successTemplate, f.Operation)
|
f.Operation = fmt.Sprintf(successTemplate, f.Operation)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AllowedFormats returns slice of string of allowed Name printing format
|
||||||
func (f *NamePrintFlags) AllowedFormats() []string {
|
func (f *NamePrintFlags) AllowedFormats() []string {
|
||||||
if f == nil {
|
if f == nil {
|
||||||
return []string{}
|
return []string{}
|
||||||
|
@ -27,6 +27,8 @@ import (
|
|||||||
"k8s.io/cli-runtime/pkg/printers"
|
"k8s.io/cli-runtime/pkg/printers"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// NoCompatiblePrinterError is a struct that contains error information.
|
||||||
|
// It will be constructed when a invalid printing format is provided
|
||||||
type NoCompatiblePrinterError struct {
|
type NoCompatiblePrinterError struct {
|
||||||
OutputFormat *string
|
OutputFormat *string
|
||||||
AllowedFormats []string
|
AllowedFormats []string
|
||||||
@ -43,6 +45,8 @@ func (e NoCompatiblePrinterError) Error() string {
|
|||||||
return fmt.Sprintf("unable to match a printer suitable for the output format %q, allowed formats are: %s", output, strings.Join(e.AllowedFormats, ","))
|
return fmt.Sprintf("unable to match a printer suitable for the output format %q, allowed formats are: %s", output, strings.Join(e.AllowedFormats, ","))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsNoCompatiblePrinterError returns true if it is a not a compatible printer
|
||||||
|
// otherwise it will return false
|
||||||
func IsNoCompatiblePrinterError(err error) bool {
|
func IsNoCompatiblePrinterError(err error) bool {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return false
|
return false
|
||||||
@ -69,10 +73,12 @@ type PrintFlags struct {
|
|||||||
OutputFlagSpecified func() bool
|
OutputFlagSpecified func() bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Complete sets NamePrintFlags operation flag from sucessTemplate
|
||||||
func (f *PrintFlags) Complete(successTemplate string) error {
|
func (f *PrintFlags) Complete(successTemplate string) error {
|
||||||
return f.NamePrintFlags.Complete(successTemplate)
|
return f.NamePrintFlags.Complete(successTemplate)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AllowedFormats returns slice of string of allowed JSONYaml/Name/Template printing format
|
||||||
func (f *PrintFlags) AllowedFormats() []string {
|
func (f *PrintFlags) AllowedFormats() []string {
|
||||||
ret := []string{}
|
ret := []string{}
|
||||||
ret = append(ret, f.JSONYamlPrintFlags.AllowedFormats()...)
|
ret = append(ret, f.JSONYamlPrintFlags.AllowedFormats()...)
|
||||||
@ -81,6 +87,10 @@ func (f *PrintFlags) AllowedFormats() []string {
|
|||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ToPrinter returns a printer capable of
|
||||||
|
// handling --output or --template printing.
|
||||||
|
// Returns false if the specified outputFormat does not match a supported format.
|
||||||
|
// Supported format types can be found in pkg/printers/printers.go
|
||||||
func (f *PrintFlags) ToPrinter() (printers.ResourcePrinter, error) {
|
func (f *PrintFlags) ToPrinter() (printers.ResourcePrinter, error) {
|
||||||
outputFormat := ""
|
outputFormat := ""
|
||||||
if f.OutputFormat != nil {
|
if f.OutputFormat != nil {
|
||||||
@ -118,6 +128,8 @@ func (f *PrintFlags) ToPrinter() (printers.ResourcePrinter, error) {
|
|||||||
return nil, NoCompatiblePrinterError{OutputFormat: f.OutputFormat, AllowedFormats: f.AllowedFormats()}
|
return nil, NoCompatiblePrinterError{OutputFormat: f.OutputFormat, AllowedFormats: f.AllowedFormats()}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AddFlags receives a *cobra.Command reference and binds
|
||||||
|
// flags related to JSON/Yaml/Name/Template printing to it
|
||||||
func (f *PrintFlags) AddFlags(cmd *cobra.Command) {
|
func (f *PrintFlags) AddFlags(cmd *cobra.Command) {
|
||||||
f.JSONYamlPrintFlags.AddFlags(cmd)
|
f.JSONYamlPrintFlags.AddFlags(cmd)
|
||||||
f.NamePrintFlags.AddFlags(cmd)
|
f.NamePrintFlags.AddFlags(cmd)
|
||||||
@ -145,6 +157,7 @@ func (f *PrintFlags) WithTypeSetter(scheme *runtime.Scheme) *PrintFlags {
|
|||||||
return f
|
return f
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewPrintFlags returns a default *PrintFlags
|
||||||
func NewPrintFlags(operation string) *PrintFlags {
|
func NewPrintFlags(operation string) *PrintFlags {
|
||||||
outputFormat := ""
|
outputFormat := ""
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/evanphx/json-patch"
|
jsonpatch "github.com/evanphx/json-patch"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/spf13/pflag"
|
"github.com/spf13/pflag"
|
||||||
|
|
||||||
@ -74,6 +74,7 @@ func (f *RecordFlags) Complete(cmd *cobra.Command) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CompleteWithChangeCause alters changeCause value with a new cause
|
||||||
func (f *RecordFlags) CompleteWithChangeCause(cause string) error {
|
func (f *RecordFlags) CompleteWithChangeCause(cause string) error {
|
||||||
if f == nil {
|
if f == nil {
|
||||||
return nil
|
return nil
|
||||||
|
@ -47,6 +47,7 @@ type GoTemplatePrintFlags struct {
|
|||||||
TemplateArgument *string
|
TemplateArgument *string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AllowedFormats returns slice of string of allowed GoTemplatePrint printing format
|
||||||
func (f *GoTemplatePrintFlags) AllowedFormats() []string {
|
func (f *GoTemplatePrintFlags) AllowedFormats() []string {
|
||||||
formats := make([]string, 0, len(templateFormats))
|
formats := make([]string, 0, len(templateFormats))
|
||||||
for format := range templateFormats {
|
for format := range templateFormats {
|
||||||
@ -90,7 +91,7 @@ func (f *GoTemplatePrintFlags) ToPrinter(templateFormat string) (printers.Resour
|
|||||||
if templateFormat == "templatefile" || templateFormat == "go-template-file" {
|
if templateFormat == "templatefile" || templateFormat == "go-template-file" {
|
||||||
data, err := ioutil.ReadFile(templateValue)
|
data, err := ioutil.ReadFile(templateValue)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("error reading --template %s, %v\n", templateValue, err)
|
return nil, fmt.Errorf("error reading --template %s, %v", templateValue, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
templateValue = string(data)
|
templateValue = string(data)
|
||||||
@ -98,7 +99,7 @@ func (f *GoTemplatePrintFlags) ToPrinter(templateFormat string) (printers.Resour
|
|||||||
|
|
||||||
p, err := printers.NewGoTemplatePrinter([]byte(templateValue))
|
p, err := printers.NewGoTemplatePrinter([]byte(templateValue))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("error parsing template %s, %v\n", templateValue, err)
|
return nil, fmt.Errorf("error parsing template %s, %v", templateValue, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
allowMissingKeys := true
|
allowMissingKeys := true
|
||||||
|
Loading…
Reference in New Issue
Block a user