From 6dd8a1dfa4716f6df69e80feeb3a37fcebe38a0c Mon Sep 17 00:00:00 2001 From: hurf Date: Tue, 7 Jul 2015 11:14:28 +0800 Subject: [PATCH] Add a better help message for kubectl describe When resource type isn't given in the command, print the possible resource types. Also added the resource type description in help strings. --- docs/man/man1/kubectl-describe.1 | 6 ++++++ docs/user-guide/kubectl/kubectl_describe.md | 7 ++++++- pkg/kubectl/cmd/cmd.go | 12 +++++++++++ pkg/kubectl/cmd/describe.go | 16 ++++++++++++--- pkg/kubectl/cmd/get.go | 22 ++------------------- 5 files changed, 39 insertions(+), 24 deletions(-) diff --git a/docs/man/man1/kubectl-describe.1 b/docs/man/man1/kubectl-describe.1 index 766b6c87e30..faaa2cf58fe 100644 --- a/docs/man/man1/kubectl-describe.1 +++ b/docs/man/man1/kubectl-describe.1 @@ -26,6 +26,12 @@ $ kubectl describe RESOURCE NAME\_PREFIX will first check for an exact match on RESOURCE and NAME\_PREFIX. If no such resource exists, it will output details for every resource that has a name prefixed with NAME\_PREFIX +.PP +Possible resources include pods (po), replicationcontrollers (rc), services +(svc), nodes (no), events (ev), componentstatuses (cs), limitRanges (limits), +persistentVolumes (pv), persistentVolumeClaims (pvc), resourceQuotas (quota) +or secrets. + .SH OPTIONS .PP diff --git a/docs/user-guide/kubectl/kubectl_describe.md b/docs/user-guide/kubectl/kubectl_describe.md index 241e4774736..a8f3835fbe8 100644 --- a/docs/user-guide/kubectl/kubectl_describe.md +++ b/docs/user-guide/kubectl/kubectl_describe.md @@ -29,6 +29,11 @@ $ kubectl describe RESOURCE NAME_PREFIX will first check for an exact match on RESOURCE and NAME_PREFIX. If no such resource exists, it will output details for every resource that has a name prefixed with NAME_PREFIX +Possible resources include pods (po), replicationcontrollers (rc), services +(svc), nodes (no), events (ev), componentstatuses (cs), limitRanges (limits), +persistentVolumes (pv), persistentVolumeClaims (pvc), resourceQuotas (quota) +or secrets. + ``` kubectl describe (RESOURCE NAME_PREFIX | RESOURCE/NAME) ``` @@ -89,7 +94,7 @@ $ kubectl describe pods frontend ### SEE ALSO * [kubectl](kubectl.md) - kubectl controls the Kubernetes cluster manager -###### Auto generated by spf13/cobra at 2015-07-14 00:11:42.955631296 +0000 UTC +###### Auto generated by spf13/cobra at 2015-07-14 08:21:33.374469932 +0000 UTC diff --git a/pkg/kubectl/cmd/cmd.go b/pkg/kubectl/cmd/cmd.go index 45b5c83d4ad..f08e96514c3 100644 --- a/pkg/kubectl/cmd/cmd.go +++ b/pkg/kubectl/cmd/cmd.go @@ -90,6 +90,18 @@ __custom_func() { ;; esac } +` + valid_resources = `Valid resource types include: + * pods (aka 'po') + * replicationcontrollers (aka 'rc') + * services (aka 'svc') + * nodes (aka 'no') + * events (aka 'ev') + * secrets + * limits + * persistentVolumes (aka 'pv') + * persistentVolumeClaims (aka 'pvc') + * quota ` ) diff --git a/pkg/kubectl/cmd/describe.go b/pkg/kubectl/cmd/describe.go index f5fd6c9f609..d2f4f60579f 100644 --- a/pkg/kubectl/cmd/describe.go +++ b/pkg/kubectl/cmd/describe.go @@ -23,7 +23,7 @@ import ( "github.com/spf13/cobra" - "github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors" + apierrors "github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors" "github.com/GoogleCloudPlatform/kubernetes/pkg/api/meta" "github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl" cmdutil "github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl/cmd/util" @@ -40,7 +40,12 @@ given resource or group of resources. $ kubectl describe RESOURCE NAME_PREFIX will first check for an exact match on RESOURCE and NAME_PREFIX. If no such resource -exists, it will output details for every resource that has a name prefixed with NAME_PREFIX` +exists, it will output details for every resource that has a name prefixed with NAME_PREFIX + +Possible resources include pods (po), replicationcontrollers (rc), services +(svc), nodes (no), events (ev), componentstatuses (cs), limitRanges (limits), +persistentVolumes (pv), persistentVolumeClaims (pvc), resourceQuotas (quota) +or secrets.` describe_example = `// Describe a node $ kubectl describe nodes kubernetes-minion-emt8.c.myproject.internal @@ -78,6 +83,11 @@ func RunDescribe(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []s return err } + if len(args) == 0 { + fmt.Fprint(out, "You must specify the type of resource to describe. ", valid_resources) + return cmdutil.UsageError(cmd, "Required resource not specified.") + } + mapper, typer := f.Object() r := resource.NewBuilder(mapper, typer, f.ClientMapperForCommand()). ContinueOnError(). @@ -101,7 +111,7 @@ func RunDescribe(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []s } infos, err := r.Infos() if err != nil { - if errors.IsNotFound(err) && len(args) == 2 { + if apierrors.IsNotFound(err) && len(args) == 2 { return DescribeMatchingResources(mapper, typer, describer, f, cmdNamespace, args[0], args[1], out) } return err diff --git a/pkg/kubectl/cmd/get.go b/pkg/kubectl/cmd/get.go index 4dd0765ebcf..4762752faf9 100644 --- a/pkg/kubectl/cmd/get.go +++ b/pkg/kubectl/cmd/get.go @@ -17,7 +17,6 @@ limitations under the License. package cmd import ( - "errors" "fmt" "io" @@ -101,25 +100,8 @@ func RunGet(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []string } if len(args) == 0 { - fmt.Fprint(out, ` -You must specify the type of resource to get. Valid resource types include: - * componentStatuses (aka 'cs') - * endpoints (aka 'ep') - * events (aka 'ev') - * limits - * namespaces - * nodes (aka 'no') - * persistentVolumeClaims (aka 'pvc') - * persistentVolumes (aka 'pv') - * pods (aka 'po') - * podTemplates - * quota - * replicationcontrollers (aka 'rc') - * secrets - * serviceAccounts - * services -`) - return errors.New("Required resource not specified.") + fmt.Fprint(out, "You must specify the type of resource to get. ", valid_resources) + return cmdutil.UsageError(cmd, "Required resource not specified.") } // handle watch separately since we cannot watch multiple resource types