From f5b7a6e2a3c4b7a08f63bc28ba684b8360af71cb Mon Sep 17 00:00:00 2001 From: lojies Date: Tue, 23 Aug 2016 09:40:57 +0800 Subject: [PATCH] add valid resources when args is nil --- pkg/kubectl/cmd/cmd.go | 2 +- pkg/kubectl/cmd/explain.go | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/pkg/kubectl/cmd/cmd.go b/pkg/kubectl/cmd/cmd.go index 273e59a16e3..8124d98fe1e 100644 --- a/pkg/kubectl/cmd/cmd.go +++ b/pkg/kubectl/cmd/cmd.go @@ -245,7 +245,7 @@ Find more information at https://github.com/kubernetes/kubernetes.`, Message: "Basic Commands (Intermediate):", Commands: []*cobra.Command{ NewCmdGet(f, out, err), - NewCmdExplain(f, out), + NewCmdExplain(f, out, err), NewCmdEdit(f, out, err), NewCmdDelete(f, out), }, diff --git a/pkg/kubectl/cmd/explain.go b/pkg/kubectl/cmd/explain.go index 6ac488099be..36ab144d12e 100644 --- a/pkg/kubectl/cmd/explain.go +++ b/pkg/kubectl/cmd/explain.go @@ -17,6 +17,7 @@ limitations under the License. package cmd import ( + "fmt" "io" "github.com/renstrom/dedent" @@ -43,14 +44,14 @@ var ( ) // NewCmdExplain returns a cobra command for swagger docs -func NewCmdExplain(f *cmdutil.Factory, out io.Writer) *cobra.Command { +func NewCmdExplain(f *cmdutil.Factory, out, cmdErr io.Writer) *cobra.Command { cmd := &cobra.Command{ Use: "explain RESOURCE", Short: "Documentation of resources", Long: explainLong, Example: explainExamples, Run: func(cmd *cobra.Command, args []string) { - err := RunExplain(f, out, cmd, args) + err := RunExplain(f, out, cmdErr, cmd, args) cmdutil.CheckErr(err) }, } @@ -60,8 +61,12 @@ func NewCmdExplain(f *cmdutil.Factory, out io.Writer) *cobra.Command { } // RunExplain executes the appropriate steps to print a model's documentation -func RunExplain(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []string) error { - if len(args) != 1 { +func RunExplain(f *cmdutil.Factory, out, cmdErr io.Writer, cmd *cobra.Command, args []string) error { + if len(args) == 0 { + fmt.Fprint(cmdErr, "You must specify the type of resource to explain. ", valid_resources) + return cmdutil.UsageError(cmd, "Required resource not specified.") + } + if len(args) > 1 { return cmdutil.UsageError(cmd, "We accept only this format: explain RESOURCE") }