From 6a34285e8479855e0f3ee238dba25dcd5b388478 Mon Sep 17 00:00:00 2001 From: Chao Wang Date: Thu, 9 Nov 2017 13:34:21 +0800 Subject: [PATCH] =?UTF-8?q?Using=20--show-labels=20with=20incompatible=20?= =?UTF-8?q?=E2=80=98kubectl=20get=E2=80=99=20arguments=20should=20error=20?= =?UTF-8?q?out?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/kubectl/cmd/resource/get.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pkg/kubectl/cmd/resource/get.go b/pkg/kubectl/cmd/resource/get.go index 9693111839..41e8b9a7ce 100644 --- a/pkg/kubectl/cmd/resource/get.go +++ b/pkg/kubectl/cmd/resource/get.go @@ -145,7 +145,7 @@ func NewCmdGet(f cmdutil.Factory, out io.Writer, errOut io.Writer) *cobra.Comman Example: getExample, Run: func(cmd *cobra.Command, args []string) { cmdutil.CheckErr(options.Complete(f, cmd, args)) - cmdutil.CheckErr(options.Validate()) + cmdutil.CheckErr(options.Validate(cmd)) cmdutil.CheckErr(options.Run(f, cmd, args)) }, 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. -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) { 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 }