Use cobra Example field

This commit is contained in:
Corey Johnson 2020-06-09 08:43:22 -07:00
parent 4d182c4314
commit 51353c79d6
2 changed files with 4 additions and 6 deletions

View file

@ -79,8 +79,8 @@ func rootHelpFunc(command *cobra.Command, args []string) {
if command.HasLocalFlags() {
helpEntries = append(helpEntries, helpEntry{"FLAGS", strings.TrimRight(command.LocalFlags().FlagUsages(), "\n")})
}
if _, ok := command.Annotations["help:examples"]; ok {
helpEntries = append(helpEntries, helpEntry{"EXAMPLES", command.Annotations["help:examples"]})
if command.Example != "" {
helpEntries = append(helpEntries, helpEntry{"EXAMPLES", command.Example})
}
if _, ok := command.Annotations["help:learnmore"]; ok {
helpEntries = append(helpEntries, helpEntry{"LEARN MORE", command.Annotations["help:learnmore"]})

View file

@ -93,12 +93,10 @@ var RootCmd = &cobra.Command{
SilenceErrors: true,
SilenceUsage: true,
Annotations: map[string]string{
"help:examples": `
$ gh issue create
Example: `$ gh issue create
$ gh repo clone
$ gh pr checkout 321`,
Annotations: map[string]string{
"help:learnmore": `
Use "gh <command> <subcommand> --help" for more information about a command.
Read the manual at <http://cli.github.com/manual>`,