From 51353c79d6f669cf0c7f951eafca621e8658f4aa Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Tue, 9 Jun 2020 08:43:22 -0700 Subject: [PATCH] Use cobra `Example` field --- command/help.go | 4 ++-- command/root.go | 6 ++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/command/help.go b/command/help.go index d57763133..b44444b2b 100644 --- a/command/help.go +++ b/command/help.go @@ -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"]}) diff --git a/command/root.go b/command/root.go index ee1a94143..2bda468d0 100644 --- a/command/root.go +++ b/command/root.go @@ -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 --help" for more information about a command. Read the manual at `,