From b0f8a541fa391310d6649327759310561ef31bc2 Mon Sep 17 00:00:00 2001 From: Louis Taylor Date: Thu, 18 Jan 2018 00:02:48 +0000 Subject: [PATCH] kubectl: make error with resource list prettier Previously, running commands like `kubectl get` with no further arguments would print a list of valid resource types with an error messages formatted like so: * serviceaccounts (aka 'sa') * services (aka 'svc') * statefulsets (aka 'sts') * storageclasses (aka 'sc')error: Required resource not specified. Use "kubectl explain " for a detailed description of that resource (e.g. kubectl explain pods). See 'kubectl get -h' for help and examples. This commit adds extra spacing so it now looks pretty: * serviceaccounts (aka 'sa') * services (aka 'svc') * statefulsets (aka 'sts') * storageclasses (aka 'sc') error: Required resource not specified. Use "kubectl explain " for a detailed description of that resource (e.g. kubectl explain pods). See 'kubectl get -h' for help and examples. --- pkg/kubectl/cmd/describe.go | 2 +- pkg/kubectl/cmd/explain.go | 2 +- pkg/kubectl/cmd/resource/get.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/kubectl/cmd/describe.go b/pkg/kubectl/cmd/describe.go index f77304ec599..153c80536d3 100644 --- a/pkg/kubectl/cmd/describe.go +++ b/pkg/kubectl/cmd/describe.go @@ -111,7 +111,7 @@ func RunDescribe(f cmdutil.Factory, out, cmdErr io.Writer, cmd *cobra.Command, a enforceNamespace = false } if len(args) == 0 && cmdutil.IsFilenameSliceEmpty(options.Filenames) { - fmt.Fprint(cmdErr, "You must specify the type of resource to describe. ", cmdutil.ValidResourceTypeList(f)) + fmt.Fprintf(cmdErr, "You must specify the type of resource to describe. %s\n\n", cmdutil.ValidResourceTypeList(f)) return cmdutil.UsageErrorf(cmd, "Required resource not specified.") } diff --git a/pkg/kubectl/cmd/explain.go b/pkg/kubectl/cmd/explain.go index d1ecf3d65d4..e1c98fea137 100644 --- a/pkg/kubectl/cmd/explain.go +++ b/pkg/kubectl/cmd/explain.go @@ -71,7 +71,7 @@ func NewCmdExplain(f cmdutil.Factory, out, cmdErr io.Writer) *cobra.Command { // RunExplain executes the appropriate steps to print a model's documentation func RunExplain(f cmdutil.Factory, out, cmdErr io.Writer, cmd *cobra.Command, args []string) error { if len(args) == 0 { - fmt.Fprintf(cmdErr, "You must specify the type of resource to explain. %s\n", cmdutil.ValidResourceTypeList(f)) + fmt.Fprintf(cmdErr, "You must specify the type of resource to explain. %s\n\n", cmdutil.ValidResourceTypeList(f)) return cmdutil.UsageErrorf(cmd, "Required resource not specified.") } if len(args) > 1 { diff --git a/pkg/kubectl/cmd/resource/get.go b/pkg/kubectl/cmd/resource/get.go index 56d458c5a78..5c4316e066f 100644 --- a/pkg/kubectl/cmd/resource/get.go +++ b/pkg/kubectl/cmd/resource/get.go @@ -203,7 +203,7 @@ func (options *GetOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args options.IncludeUninitialized = cmdutil.ShouldIncludeUninitialized(cmd, len(args) == 2) default: if len(args) == 0 && cmdutil.IsFilenameSliceEmpty(options.Filenames) { - fmt.Fprint(options.ErrOut, "You must specify the type of resource to get. ", cmdutil.ValidResourceTypeList(f)) + fmt.Fprintf(options.ErrOut, "You must specify the type of resource to get. %s\n\n", cmdutil.ValidResourceTypeList(f)) fullCmdName := cmd.Parent().CommandPath() usageString := "Required resource not specified." if len(fullCmdName) > 0 && cmdutil.IsSiblingCommandExists(cmd, "explain") {