Fixes #30562: Refactor kubectl command options to use common struct for common file params

This commit is contained in:
ymqytw
2016-08-17 11:28:07 -07:00
parent 115855bbd2
commit c67a62da49
28 changed files with 182 additions and 291 deletions

View File

@@ -33,14 +33,14 @@ import (
// PauseConfig is the start of the data required to perform the operation. As new fields are added, add them here instead of
// referencing the cmd.Flags()
type PauseConfig struct {
resource.FilenameOptions
PauseObject func(object runtime.Object) (bool, error)
Mapper meta.RESTMapper
Typer runtime.ObjectTyper
Infos []*resource.Info
Out io.Writer
Filenames []string
Recursive bool
Out io.Writer
}
var (
@@ -59,7 +59,7 @@ var (
)
func NewCmdRolloutPause(f *cmdutil.Factory, out io.Writer) *cobra.Command {
opts := &PauseConfig{}
options := &PauseConfig{}
validArgs := []string{"deployment"}
argAliases := kubectl.ResourceAliases(validArgs)
@@ -71,11 +71,11 @@ func NewCmdRolloutPause(f *cmdutil.Factory, out io.Writer) *cobra.Command {
Example: pause_example,
Run: func(cmd *cobra.Command, args []string) {
allErrs := []error{}
err := opts.CompletePause(f, cmd, out, args)
err := options.CompletePause(f, cmd, out, args)
if err != nil {
allErrs = append(allErrs, err)
}
err = opts.RunPause()
err = options.RunPause()
if err != nil {
allErrs = append(allErrs, err)
}
@@ -85,14 +85,13 @@ func NewCmdRolloutPause(f *cmdutil.Factory, out io.Writer) *cobra.Command {
ArgAliases: argAliases,
}
usage := "Filename, directory, or URL to a file identifying the resource to get from a server."
kubectl.AddJsonFilenameFlag(cmd, &opts.Filenames, usage)
cmdutil.AddRecursiveFlag(cmd, &opts.Recursive)
usage := "identifying the resource to get from a server."
cmdutil.AddFilenameOptionFlags(cmd, &options.FilenameOptions, usage)
return cmd
}
func (o *PauseConfig) CompletePause(f *cmdutil.Factory, cmd *cobra.Command, out io.Writer, args []string) error {
if len(args) == 0 && len(o.Filenames) == 0 {
if len(args) == 0 && cmdutil.IsFilenameEmpty(o.Filenames) {
return cmdutil.UsageError(cmd, cmd.Use)
}
@@ -107,7 +106,7 @@ func (o *PauseConfig) CompletePause(f *cmdutil.Factory, cmd *cobra.Command, out
r := resource.NewBuilder(o.Mapper, o.Typer, resource.ClientMapperFunc(f.ClientForMapping), f.Decoder(true)).
NamespaceParam(cmdNamespace).DefaultNamespace().
FilenameParam(enforceNamespace, o.Recursive, o.Filenames...).
FilenameParam(enforceNamespace, &o.FilenameOptions).
ResourceTypeOrNameArgs(true, args...).
ContinueOnError().
Latest().