mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-04 18:00:08 +00:00
Using --show-labels with incompatible ‘kubectl get’ arguments should error out
This commit is contained in:
parent
f34d3af809
commit
6a34285e84
@ -145,7 +145,7 @@ func NewCmdGet(f cmdutil.Factory, out io.Writer, errOut io.Writer) *cobra.Comman
|
|||||||
Example: getExample,
|
Example: getExample,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
cmdutil.CheckErr(options.Complete(f, cmd, args))
|
cmdutil.CheckErr(options.Complete(f, cmd, args))
|
||||||
cmdutil.CheckErr(options.Validate())
|
cmdutil.CheckErr(options.Validate(cmd))
|
||||||
cmdutil.CheckErr(options.Run(f, cmd, args))
|
cmdutil.CheckErr(options.Run(f, cmd, args))
|
||||||
},
|
},
|
||||||
SuggestFor: []string{"list", "ps"},
|
SuggestFor: []string{"list", "ps"},
|
||||||
@ -209,10 +209,16 @@ func (options *GetOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Validate checks the set of flags provided by the user.
|
// Validate checks the set of flags provided by the user.
|
||||||
func (options *GetOptions) Validate() error {
|
func (options *GetOptions) Validate(cmd *cobra.Command) error {
|
||||||
if len(options.Raw) > 0 && (options.Watch || options.WatchOnly || len(options.LabelSelector) > 0 || options.Export) {
|
if len(options.Raw) > 0 && (options.Watch || options.WatchOnly || len(options.LabelSelector) > 0 || options.Export) {
|
||||||
return fmt.Errorf("--raw may not be specified with other flags that filter the server request or alter the output")
|
return fmt.Errorf("--raw may not be specified with other flags that filter the server request or alter the output")
|
||||||
}
|
}
|
||||||
|
if cmdutil.GetFlagBool(cmd, "show-labels") {
|
||||||
|
outputOption := cmd.Flags().Lookup("output").Value.String()
|
||||||
|
if outputOption != "" && outputOption != "wide" {
|
||||||
|
return fmt.Errorf("--show-labels option cannot be used with %s printer", outputOption)
|
||||||
|
}
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user