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:

    <snip>
      * serviceaccounts (aka 'sa')
      * services (aka 'svc')
      * statefulsets (aka 'sts')
      * storageclasses (aka 'sc')error: Required resource not specified.
    Use "kubectl explain <resource>" 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:

    <snip>
      * serviceaccounts (aka 'sa')
      * services (aka 'svc')
      * statefulsets (aka 'sts')
      * storageclasses (aka 'sc')

    error: Required resource not specified.
    Use "kubectl explain <resource>" for a detailed description of that resource (e.g. kubectl explain pods).
    See 'kubectl get -h' for help and examples.
This commit is contained in:
Louis Taylor 2018-01-18 00:02:48 +00:00
parent bda841fa7b
commit b0f8a541fa
No known key found for this signature in database
GPG Key ID: 8E81A6DAE13E7098
3 changed files with 3 additions and 3 deletions

View File

@ -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.")
}

View File

@ -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 {

View File

@ -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") {