Fix rendering issue in "formatting" help topic (#4661)

Signed-off-by: Peter Benjamin <petermbenjamin@gmail.com>
This commit is contained in:
Peter Benjamin 2021-11-02 10:30:49 -07:00 committed by GitHub
parent d794a929da
commit 175da0f58a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2,6 +2,7 @@ package root
import (
"github.com/MakeNowJust/heredoc"
"github.com/cli/cli/v2/pkg/text"
"github.com/spf13/cobra"
)
@ -104,31 +105,32 @@ var HelpTopics = map[string]map[string]string{
- %[1]stimeago <time>%[1]s: renders a timestamp as relative to now
- %[1]stimefmt <format> <time>%[1]s: formats a timestamp using Go's Time.Format function
- %[1]struncate <length> <input>%[1]s: ensures input fits within length
EXAMPLES
# format issues as table
$ gh issue list --json number,title --template \
'{{range .}}{{tablerow (printf "#%%v" .number | autocolor "green") .title}}{{end}}'
# format a pull request using multiple tables with headers
$ gh pr view 3519 --json number,title,body,reviews,assignees --template \
'{{printf "#%%v" .number}} {{.title}}
{{.body}}
{{tablerow "ASSIGNEE" "NAME"}}{{range .assignees}}{{tablerow .login .name}}{{end}}{{tablerender}}
{{tablerow "REVIEWER" "STATE" "COMMENT"}}{{range .reviews}}{{tablerow .author.login .state .body}}{{end}}
'
`, "`"),
"example": heredoc.Doc(`
# format issues as table
$ gh issue list --json number,title --template \
'{{range .}}{{tablerow (printf "#%v" .number | autocolor "green") .title}}{{end}}'
# format a pull request using multiple tables with headers
$ gh pr view 3519 --json number,title,body,reviews,assignees --template \
'{{printf "#%v" .number}} {{.title}}
{{.body}}
{{tablerow "ASSIGNEE" "NAME"}}{{range .assignees}}{{tablerow .login .name}}{{end}}{{tablerender}}
{{tablerow "REVIEWER" "STATE" "COMMENT"}}{{range .reviews}}{{tablerow .author.login .state .body}}{{end}}
'
`),
},
}
func NewHelpTopic(topic string) *cobra.Command {
cmd := &cobra.Command{
Use: topic,
Short: HelpTopics[topic]["short"],
Long: HelpTopics[topic]["long"],
Hidden: true,
Use: topic,
Short: HelpTopics[topic]["short"],
Long: HelpTopics[topic]["long"],
Example: HelpTopics[topic]["example"],
Hidden: true,
Annotations: map[string]string{
"markdown:generate": "true",
"markdown:basename": "gh_help_" + topic,
@ -143,6 +145,10 @@ func NewHelpTopic(topic string) *cobra.Command {
func helpTopicHelpFunc(command *cobra.Command, args []string) {
command.Print(command.Long)
if command.Example != "" {
command.Printf("\n\nEXAMPLES\n")
command.Print(text.Indent(command.Example, " "))
}
}
func helpTopicUsageFunc(command *cobra.Command) error {