X Tutup
Skip to content

Commit 175da0f

Browse files
authored
Fix rendering issue in "formatting" help topic (cli#4661)
Signed-off-by: Peter Benjamin <petermbenjamin@gmail.com>
1 parent d794a92 commit 175da0f

File tree

1 file changed

+23
-17
lines changed

1 file changed

+23
-17
lines changed

pkg/cmd/root/help_topic.go

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package root
22

33
import (
44
"github.com/MakeNowJust/heredoc"
5+
"github.com/cli/cli/v2/pkg/text"
56
"github.com/spf13/cobra"
67
)
78

@@ -104,31 +105,32 @@ var HelpTopics = map[string]map[string]string{
104105
- %[1]stimeago <time>%[1]s: renders a timestamp as relative to now
105106
- %[1]stimefmt <format> <time>%[1]s: formats a timestamp using Go's Time.Format function
106107
- %[1]struncate <length> <input>%[1]s: ensures input fits within length
108+
`, "`"),
109+
"example": heredoc.Doc(`
110+
# format issues as table
111+
$ gh issue list --json number,title --template \
112+
'{{range .}}{{tablerow (printf "#%v" .number | autocolor "green") .title}}{{end}}'
107113
108-
EXAMPLES
109-
# format issues as table
110-
$ gh issue list --json number,title --template \
111-
'{{range .}}{{tablerow (printf "#%%v" .number | autocolor "green") .title}}{{end}}'
112-
113-
# format a pull request using multiple tables with headers
114-
$ gh pr view 3519 --json number,title,body,reviews,assignees --template \
115-
'{{printf "#%%v" .number}} {{.title}}
114+
# format a pull request using multiple tables with headers
115+
$ gh pr view 3519 --json number,title,body,reviews,assignees --template \
116+
'{{printf "#%v" .number}} {{.title}}
116117
117-
{{.body}}
118+
{{.body}}
118119
119-
{{tablerow "ASSIGNEE" "NAME"}}{{range .assignees}}{{tablerow .login .name}}{{end}}{{tablerender}}
120-
{{tablerow "REVIEWER" "STATE" "COMMENT"}}{{range .reviews}}{{tablerow .author.login .state .body}}{{end}}
121-
'
122-
`, "`"),
120+
{{tablerow "ASSIGNEE" "NAME"}}{{range .assignees}}{{tablerow .login .name}}{{end}}{{tablerender}}
121+
{{tablerow "REVIEWER" "STATE" "COMMENT"}}{{range .reviews}}{{tablerow .author.login .state .body}}{{end}}
122+
'
123+
`),
123124
},
124125
}
125126

126127
func NewHelpTopic(topic string) *cobra.Command {
127128
cmd := &cobra.Command{
128-
Use: topic,
129-
Short: HelpTopics[topic]["short"],
130-
Long: HelpTopics[topic]["long"],
131-
Hidden: true,
129+
Use: topic,
130+
Short: HelpTopics[topic]["short"],
131+
Long: HelpTopics[topic]["long"],
132+
Example: HelpTopics[topic]["example"],
133+
Hidden: true,
132134
Annotations: map[string]string{
133135
"markdown:generate": "true",
134136
"markdown:basename": "gh_help_" + topic,
@@ -143,6 +145,10 @@ func NewHelpTopic(topic string) *cobra.Command {
143145

144146
func helpTopicHelpFunc(command *cobra.Command, args []string) {
145147
command.Print(command.Long)
148+
if command.Example != "" {
149+
command.Printf("\n\nEXAMPLES\n")
150+
command.Print(text.Indent(command.Example, " "))
151+
}
146152
}
147153

148154
func helpTopicUsageFunc(command *cobra.Command) error {

0 commit comments

Comments
 (0)
X Tutup