mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-01 07:47:56 +00:00
Merge pull request #69760 from Pingan2017/validate-args
validate args for kubectl api-versions/api-resources command
This commit is contained in:
commit
007ad9179c
@ -86,7 +86,8 @@ func NewCmdApiResources(f cmdutil.Factory, ioStreams genericclioptions.IOStreams
|
|||||||
Long: "Print the supported API resources on the server",
|
Long: "Print the supported API resources on the server",
|
||||||
Example: apiresourcesExample,
|
Example: apiresourcesExample,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
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))
|
cmdutil.CheckErr(o.RunApiResources(cmd, f))
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -101,7 +102,7 @@ func NewCmdApiResources(f cmdutil.Factory, ioStreams genericclioptions.IOStreams
|
|||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *ApiResourcesOptions) Validate(cmd *cobra.Command) error {
|
func (o *ApiResourcesOptions) Validate() error {
|
||||||
supportedOutputTypes := sets.NewString("", "wide", "name")
|
supportedOutputTypes := sets.NewString("", "wide", "name")
|
||||||
if !supportedOutputTypes.Has(o.Output) {
|
if !supportedOutputTypes.Has(o.Output) {
|
||||||
return fmt.Errorf("--output %v is not available", 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
|
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 {
|
func (o *ApiResourcesOptions) RunApiResources(cmd *cobra.Command, f cmdutil.Factory) error {
|
||||||
w := printers.GetNewTabWriter(o.Out)
|
w := printers.GetNewTabWriter(o.Out)
|
||||||
defer w.Flush()
|
defer w.Flush()
|
||||||
|
@ -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\"",
|
Long: "Print the supported API versions on the server, in the form of \"group/version\"",
|
||||||
Example: apiversionsExample,
|
Example: apiversionsExample,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
cmdutil.CheckErr(o.Complete(f))
|
cmdutil.CheckErr(o.Complete(f, cmd, args))
|
||||||
cmdutil.CheckErr(o.RunApiVersions())
|
cmdutil.CheckErr(o.RunApiVersions())
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
return cmd
|
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
|
var err error
|
||||||
o.discoveryClient, err = f.ToDiscoveryClient()
|
o.discoveryClient, err = f.ToDiscoveryClient()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user