Fixes #30562: Refactor kubectl command options to use common struct for common file params
This commit is contained in:
@@ -36,11 +36,12 @@ import (
|
||||
|
||||
// AnnotateOptions have the data required to perform the annotate operation
|
||||
type AnnotateOptions struct {
|
||||
resource.FilenameOptions
|
||||
|
||||
resources []string
|
||||
newAnnotations map[string]string
|
||||
removeAnnotations []string
|
||||
builder *resource.Builder
|
||||
filenames []string
|
||||
selector string
|
||||
|
||||
overwrite bool
|
||||
@@ -53,8 +54,6 @@ type AnnotateOptions struct {
|
||||
f *cmdutil.Factory
|
||||
out io.Writer
|
||||
cmd *cobra.Command
|
||||
|
||||
recursive bool
|
||||
}
|
||||
|
||||
var (
|
||||
@@ -128,9 +127,8 @@ func NewCmdAnnotate(f *cmdutil.Factory, out io.Writer) *cobra.Command {
|
||||
cmd.Flags().BoolVar(&options.overwrite, "overwrite", false, "If true, allow annotations to be overwritten, otherwise reject annotation updates that overwrite existing annotations.")
|
||||
cmd.Flags().BoolVar(&options.all, "all", false, "select all resources in the namespace of the specified resource types")
|
||||
cmd.Flags().StringVar(&options.resourceVersion, "resource-version", "", "If non-empty, the annotation update will only succeed if this is the current resource-version for the object. Only valid when specifying a single resource.")
|
||||
usage := "Filename, directory, or URL to a file identifying the resource to update the annotation"
|
||||
kubectl.AddJsonFilenameFlag(cmd, &options.filenames, usage)
|
||||
cmdutil.AddRecursiveFlag(cmd, &options.recursive)
|
||||
usage := "identifying the resource to update the annotation"
|
||||
cmdutil.AddFilenameOptionFlags(cmd, &options.FilenameOptions, usage)
|
||||
cmdutil.AddRecordFlag(cmd)
|
||||
return cmd
|
||||
}
|
||||
@@ -150,7 +148,7 @@ func (o *AnnotateOptions) Complete(f *cmdutil.Factory, out io.Writer, cmd *cobra
|
||||
return err
|
||||
}
|
||||
o.resources = resources
|
||||
if len(o.resources) < 1 && len(o.filenames) == 0 {
|
||||
if len(o.resources) < 1 && cmdutil.IsFilenameEmpty(o.Filenames) {
|
||||
return fmt.Errorf("one or more resources must be specified as <resource> <name> or <resource>/<name>")
|
||||
}
|
||||
if len(annotationArgs) < 1 {
|
||||
@@ -168,7 +166,7 @@ func (o *AnnotateOptions) Complete(f *cmdutil.Factory, out io.Writer, cmd *cobra
|
||||
o.builder = resource.NewBuilder(mapper, typer, resource.ClientMapperFunc(f.ClientForMapping), f.Decoder(true)).
|
||||
ContinueOnError().
|
||||
NamespaceParam(namespace).DefaultNamespace().
|
||||
FilenameParam(enforceNamespace, o.recursive, o.filenames...).
|
||||
FilenameParam(enforceNamespace, &o.FilenameOptions).
|
||||
SelectorParam(o.selector).
|
||||
ResourceTypeOrNameArgs(o.all, o.resources...).
|
||||
Flatten().
|
||||
|
Reference in New Issue
Block a user