spf13/cobra

Cobra SetUsageTemplate() overrides the help message

almahfudhi opened this issue · 1 comments

I have an issue with the way Cobra shows Usage section in Help message. I have rootCmd that has sub-commands and flags. Both can be given at the same time. Cobra shows the Usage section as:

This is a root command
Usage:
    rootCmd [flags]
    rootCmd [command]
    
Available Commands:
    print         print a message
    list            list version
    
Flags:
-h, --help          help message
-v, --verbose     verbose

it might raise confusion as this indicates either flags or commands can be given at a time, which is not helpful.
I want only the Usage section to be modified, and leave the rest of the help message as is.
desired output:

  This is a root command
Usage:
    rootCmd [flags] [command]
    
Available Commands:
    print         print a message
    list            list version
    
Flags:
-h, --help          help message
-v, --verbose     verbose

[flags] and [commands] are in the same line

using SetUsageTemplate completely overrides the help message, hence removing available commands and flags section

You’ll have to override the default help message to suit your needs