Skip to content

Commit 0ccdae1

Browse files
author
vilmibm
committed
fix for color fns, slightly generalize
1 parent 9d12dcf commit 0ccdae1

File tree

3 files changed

+35
-23
lines changed

3 files changed

+35
-23
lines changed

pkg/cmd/root/help_reference.go

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,42 +4,33 @@ import (
44
"fmt"
55
"strings"
66

7+
"github.com/cli/cli/pkg/iostreams"
78
"github.com/cli/cli/pkg/text"
8-
"github.com/cli/cli/utils"
99
"github.com/spf13/cobra"
1010
)
1111

12-
func ReferenceHelpTopic(command *cobra.Command) *cobra.Command {
13-
reftext := fmt.Sprintf("%s reference\n\n", utils.Bold("gh"))
12+
func referenceHelpFn(cmd *cobra.Command, io *iostreams.IOStreams) func() string {
13+
cs := io.ColorScheme()
14+
return func() string {
15+
reftext := fmt.Sprintf("%s reference\n\n", cs.Bold("gh"))
1416

15-
for _, c := range command.Commands() {
16-
reftext += cmdRef(c, 0)
17+
for _, c := range cmd.Commands() {
18+
reftext += cmdRef(cs, c, 0)
19+
}
20+
return reftext
1721
}
18-
19-
ref := &cobra.Command{
20-
Use: "reference",
21-
Long: reftext,
22-
Hidden: true,
23-
Args: cobra.NoArgs,
24-
Run: helpTopicHelpFunc,
25-
}
26-
27-
ref.SetHelpFunc(helpTopicHelpFunc)
28-
ref.SetUsageFunc(helpTopicUsageFunc)
29-
30-
return ref
3122
}
3223

33-
func cmdRef(cmd *cobra.Command, lvl int) string {
24+
func cmdRef(cs *iostreams.ColorScheme, cmd *cobra.Command, lvl int) string {
3425
ref := ""
3526

3627
if cmd.Hidden {
3728
return ref
3829
}
3930

40-
cmdColor := utils.Bold
31+
cmdColor := cs.Bold
4132
if lvl > 0 {
42-
cmdColor = utils.Cyan
33+
cmdColor = cs.Cyan
4334
}
4435

4536
// Name + Description
@@ -56,7 +47,7 @@ func cmdRef(cmd *cobra.Command, lvl int) string {
5647
// Subcommands
5748
subcommands := cmd.Commands()
5849
for _, c := range subcommands {
59-
ref += cmdRef(c, lvl+1)
50+
ref += cmdRef(cs, c, lvl+1)
6051
}
6152

6253
if len(subcommands) == 0 {

pkg/cmd/root/help_topic.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,26 @@ var HelpTopics = map[string]map[string]string{
4747
},
4848
}
4949

50+
func NewHelpTopicFn(topic, short string, fn func() string) *cobra.Command {
51+
cmd := &cobra.Command{
52+
Use: topic,
53+
Short: short,
54+
Long: fn(),
55+
Hidden: true,
56+
Args: cobra.NoArgs,
57+
Run: helpTopicHelpFunc,
58+
Annotations: map[string]string{
59+
"markdown:generate": "true",
60+
"markdown:basename": "gh_help_" + topic,
61+
},
62+
}
63+
64+
cmd.SetHelpFunc(helpTopicHelpFunc)
65+
cmd.SetUsageFunc(helpTopicUsageFunc)
66+
67+
return cmd
68+
}
69+
5070
func NewHelpTopic(topic string) *cobra.Command {
5171
cmd := &cobra.Command{
5272
Use: topic,

pkg/cmd/root/root.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ func NewCmdRoot(f *cmdutil.Factory, version, buildDate string) *cobra.Command {
9292

9393
// Help topics
9494
cmd.AddCommand(NewHelpTopic("environment"))
95-
cmd.AddCommand(ReferenceHelpTopic(cmd))
95+
cmd.AddCommand(NewHelpTopicFn("reference", "Full reference for gh",
96+
referenceHelpFn(cmd, f.IOStreams)))
9697

9798
cmdutil.DisableAuthCheck(cmd)
9899

0 commit comments

Comments
 (0)