Skip to content

Commit 9d12dcf

Browse files
author
vilmibm
committed
Merge remote-tracking branch 'origin/trunk' into cmd-reference-1734
2 parents 9d8f9b6 + 9edcd68 commit 9d12dcf

File tree

4 files changed

+46
-31
lines changed

4 files changed

+46
-31
lines changed

cmd/gen-docs/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ func main() {
3838

3939
io, _, _, _ := iostreams.Test()
4040
rootCmd := root.NewCmdRoot(&cmdutil.Factory{IOStreams: io}, "", "")
41+
rootCmd.InitDefaultHelpCmd()
4142

4243
err := os.MkdirAll(*dir, 0755)
4344
if err != nil {

internal/docs/markdown.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,21 @@ func GenMarkdownTree(cmd *cobra.Command, dir string) error {
8282
// with custom filePrepender and linkHandler.
8383
func GenMarkdownTreeCustom(cmd *cobra.Command, dir string, filePrepender, linkHandler func(string) string) error {
8484
for _, c := range cmd.Commands() {
85-
if !c.IsAvailableCommand() || c.IsAdditionalHelpTopicCommand() {
85+
_, forceGeneration := c.Annotations["markdown:generate"]
86+
if c.Hidden && !forceGeneration {
8687
continue
8788
}
89+
8890
if err := GenMarkdownTreeCustom(c, dir, filePrepender, linkHandler); err != nil {
8991
return err
9092
}
9193
}
9294

9395
basename := strings.Replace(cmd.CommandPath(), " ", "_", -1) + ".md"
96+
if basenameOverride, found := cmd.Annotations["markdown:basename"]; found {
97+
basename = basenameOverride + ".md"
98+
}
99+
94100
filename := filepath.Join(dir, basename)
95101
f, err := os.Create(filename)
96102
if err != nil {

pkg/cmd/repo/credits/credits.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ func NewCmdCredits(f *cmdutil.Factory, runF func(*CreditsOptions) error) *cobra.
4545
Example: heredoc.Doc(`
4646
# see a credits animation for this project
4747
$ gh credits
48-
48+
4949
# display a non-animated thank you
5050
$ gh credits -s
51-
51+
5252
# just print the contributors, one per line
5353
$ gh credits | cat
5454
`),

pkg/cmd/root/help_topic.go

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,52 +5,60 @@ import (
55
"github.com/spf13/cobra"
66
)
77

8-
func NewHelpTopic(topic string) *cobra.Command {
9-
topicContent := make(map[string]string)
10-
11-
topicContent["environment"] = heredoc.Doc(`
12-
GITHUB_TOKEN: an authentication token for github.com API requests. Setting this avoids
13-
being prompted to authenticate and takes precedence over previously stored credentials.
8+
var HelpTopics = map[string]map[string]string{
9+
"environment": {
10+
"short": "Environment variables that can be used with gh",
11+
"long": heredoc.Doc(`
12+
GITHUB_TOKEN: an authentication token for github.com API requests. Setting this avoids
13+
being prompted to authenticate and takes precedence over previously stored credentials.
1414
15-
GITHUB_ENTERPRISE_TOKEN: an authentication token for API requests to GitHub Enterprise.
15+
GITHUB_ENTERPRISE_TOKEN: an authentication token for API requests to GitHub Enterprise.
1616
17-
GH_REPO: specify the GitHub repository in the "[HOST/]OWNER/REPO" format for commands
18-
that otherwise operate on a local repository.
17+
GH_REPO: specify the GitHub repository in the "[HOST/]OWNER/REPO" format for commands
18+
that otherwise operate on a local repository.
1919
20-
GH_HOST: specify the GitHub hostname for commands that would otherwise assume
21-
the "github.com" host when not in a context of an existing repository.
20+
GH_HOST: specify the GitHub hostname for commands that would otherwise assume
21+
the "github.com" host when not in a context of an existing repository.
2222
23-
GH_EDITOR, GIT_EDITOR, VISUAL, EDITOR (in order of precedence): the editor tool to use
24-
for authoring text.
23+
GH_EDITOR, GIT_EDITOR, VISUAL, EDITOR (in order of precedence): the editor tool to use
24+
for authoring text.
2525
26-
BROWSER: the web browser to use for opening links.
26+
BROWSER: the web browser to use for opening links.
2727
28-
DEBUG: set to any value to enable verbose output to standard error. Include values "api"
29-
or "oauth" to print detailed information about HTTP requests or authentication flow.
28+
DEBUG: set to any value to enable verbose output to standard error. Include values "api"
29+
or "oauth" to print detailed information about HTTP requests or authentication flow.
3030
31-
GH_PAGER, PAGER (in order of precedence): a terminal paging program to send standard output to, e.g. "less".
31+
GH_PAGER, PAGER (in order of precedence): a terminal paging program to send standard output to, e.g. "less".
3232
33-
GLAMOUR_STYLE: the style to use for rendering Markdown. See
34-
https://github.com/charmbracelet/glamour#styles
33+
GLAMOUR_STYLE: the style to use for rendering Markdown. See
34+
https://github.com/charmbracelet/glamour#styles
3535
36-
NO_COLOR: set to any value to avoid printing ANSI escape sequences for color output.
36+
NO_COLOR: set to any value to avoid printing ANSI escape sequences for color output.
3737
38-
CLICOLOR: set to "0" to disable printing ANSI colors in output.
38+
CLICOLOR: set to "0" to disable printing ANSI colors in output.
3939
40-
CLICOLOR_FORCE: set to a value other than "0" to keep ANSI colors in output
41-
even when the output is piped.
40+
CLICOLOR_FORCE: set to a value other than "0" to keep ANSI colors in output
41+
even when the output is piped.
4242
43-
GH_NO_UPDATE_NOTIFIER: set to any value to disable update notifications. By default, gh
44-
checks for new releases once every 24 hours and displays an upgrade notice on standard
45-
error if a newer version was found.
46-
`)
43+
GH_NO_UPDATE_NOTIFIER: set to any value to disable update notifications. By default, gh
44+
checks for new releases once every 24 hours and displays an upgrade notice on standard
45+
error if a newer version was found.
46+
`),
47+
},
48+
}
4749

50+
func NewHelpTopic(topic string) *cobra.Command {
4851
cmd := &cobra.Command{
4952
Use: topic,
50-
Long: topicContent[topic],
53+
Short: HelpTopics[topic]["short"],
54+
Long: HelpTopics[topic]["long"],
5155
Hidden: true,
5256
Args: cobra.NoArgs,
5357
Run: helpTopicHelpFunc,
58+
Annotations: map[string]string{
59+
"markdown:generate": "true",
60+
"markdown:basename": "gh_help_" + topic,
61+
},
5462
}
5563

5664
cmd.SetHelpFunc(helpTopicHelpFunc)

0 commit comments

Comments
 (0)