validte args for kubectl api-versions/api-resources

pull/58/head
Pingan2017 2018-10-13 14:31:06 +08:00
parent d84c43120e
commit 2b2d8ba8c1
2 changed files with 15 additions and 4 deletions

View File

@ -86,7 +86,8 @@ func NewCmdApiResources(f cmdutil.Factory, ioStreams genericclioptions.IOStreams
Long: "Print the supported API resources on the server",
Example: apiresourcesExample,
Run: func(cmd *cobra.Command, args []string) {
cmdutil.CheckErr(o.Validate(cmd))
cmdutil.CheckErr(o.Complete(cmd, args))
cmdutil.CheckErr(o.Validate())
cmdutil.CheckErr(o.RunApiResources(cmd, f))
},
}
@ -101,7 +102,7 @@ func NewCmdApiResources(f cmdutil.Factory, ioStreams genericclioptions.IOStreams
return cmd
}
func (o *ApiResourcesOptions) Validate(cmd *cobra.Command) error {
func (o *ApiResourcesOptions) Validate() error {
supportedOutputTypes := sets.NewString("", "wide", "name")
if !supportedOutputTypes.Has(o.Output) {
return fmt.Errorf("--output %v is not available", o.Output)
@ -109,6 +110,13 @@ func (o *ApiResourcesOptions) Validate(cmd *cobra.Command) error {
return nil
}
func (o *ApiResourcesOptions) Complete(cmd *cobra.Command, args []string) error {
if len(args) != 0 {
return cmdutil.UsageErrorf(cmd, "unexpected args: %v", args)
}
return nil
}
func (o *ApiResourcesOptions) RunApiResources(cmd *cobra.Command, f cmdutil.Factory) error {
w := printers.GetNewTabWriter(o.Out)
defer w.Flush()

View File

@ -56,14 +56,17 @@ func NewCmdApiVersions(f cmdutil.Factory, ioStreams genericclioptions.IOStreams)
Long: "Print the supported API versions on the server, in the form of \"group/version\"",
Example: apiversionsExample,
Run: func(cmd *cobra.Command, args []string) {
cmdutil.CheckErr(o.Complete(f))
cmdutil.CheckErr(o.Complete(f, cmd, args))
cmdutil.CheckErr(o.RunApiVersions())
},
}
return cmd
}
func (o *ApiVersionsOptions) Complete(f cmdutil.Factory) error {
func (o *ApiVersionsOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []string) error {
if len(args) != 0 {
return cmdutil.UsageErrorf(cmd, "unexpected args: %v", args)
}
var err error
o.discoveryClient, err = f.ToDiscoveryClient()
if err != nil {