Fix rendering issue in "formatting" help topic (#4661)
Signed-off-by: Peter Benjamin <petermbenjamin@gmail.com>
This commit is contained in:
parent
d794a929da
commit
175da0f58a
1 changed files with 25 additions and 19 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue