Use the pflag StringSlice instead of implementing it ourselves
Saves code and makes our code easier to read because we just use normal []string instead of custom type.
This commit is contained in:
@@ -23,7 +23,6 @@ import (
|
||||
"k8s.io/kubernetes/pkg/kubectl"
|
||||
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
|
||||
"k8s.io/kubernetes/pkg/kubectl/resource"
|
||||
"k8s.io/kubernetes/pkg/util"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -48,9 +47,6 @@ $ kubectl stop -f path/to/resources`
|
||||
)
|
||||
|
||||
func NewCmdStop(f *cmdutil.Factory, out io.Writer) *cobra.Command {
|
||||
flags := &struct {
|
||||
Filenames util.StringList
|
||||
}{}
|
||||
cmd := &cobra.Command{
|
||||
Use: "stop (-f FILENAME | TYPE (NAME | -l label | --all))",
|
||||
Short: "Deprecated: Gracefully shut down a resource by name or filename.",
|
||||
@@ -58,12 +54,11 @@ func NewCmdStop(f *cmdutil.Factory, out io.Writer) *cobra.Command {
|
||||
Example: stop_example,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
cmdutil.CheckErr(cmdutil.ValidateOutputArgs(cmd))
|
||||
shortOutput := cmdutil.GetFlagString(cmd, "output") == "name"
|
||||
cmdutil.CheckErr(RunStop(f, cmd, args, flags.Filenames, out, shortOutput))
|
||||
cmdutil.CheckErr(RunStop(f, cmd, args, out))
|
||||
},
|
||||
}
|
||||
usage := "Filename, directory, or URL to file of resource(s) to be stopped."
|
||||
kubectl.AddJsonFilenameFlag(cmd, &flags.Filenames, usage)
|
||||
kubectl.AddJsonFilenameFlag(cmd, usage)
|
||||
cmd.Flags().StringP("selector", "l", "", "Selector (label query) to filter on.")
|
||||
cmd.Flags().Bool("all", false, "[-all] to select all the specified resources.")
|
||||
cmd.Flags().Bool("ignore-not-found", false, "Treat \"resource not found\" as a successful stop.")
|
||||
@@ -73,11 +68,13 @@ func NewCmdStop(f *cmdutil.Factory, out io.Writer) *cobra.Command {
|
||||
return cmd
|
||||
}
|
||||
|
||||
func RunStop(f *cmdutil.Factory, cmd *cobra.Command, args []string, filenames util.StringList, out io.Writer, shortOutput bool) error {
|
||||
func RunStop(f *cmdutil.Factory, cmd *cobra.Command, args []string, out io.Writer) error {
|
||||
cmdNamespace, enforceNamespace, err := f.DefaultNamespace()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
filenames := cmdutil.GetFlagStringSlice(cmd, "filename")
|
||||
mapper, typer := f.Object()
|
||||
r := resource.NewBuilder(mapper, typer, f.ClientMapperForCommand()).
|
||||
ContinueOnError().
|
||||
@@ -91,5 +88,6 @@ func RunStop(f *cmdutil.Factory, cmd *cobra.Command, args []string, filenames ut
|
||||
if r.Err() != nil {
|
||||
return r.Err()
|
||||
}
|
||||
shortOutput := cmdutil.GetFlagString(cmd, "output") == "name"
|
||||
return ReapResult(r, f, out, false, cmdutil.GetFlagBool(cmd, "ignore-not-found"), cmdutil.GetFlagDuration(cmd, "timeout"), cmdutil.GetFlagInt(cmd, "grace-period"), shortOutput, mapper)
|
||||
}
|
||||
|
Reference in New Issue
Block a user