(f *cmdutil.Factory, command *cobra.Command, _ []string)
| 88 | } |
| 89 | |
| 90 | func rootHelpFunc(f *cmdutil.Factory, command *cobra.Command, _ []string) { |
| 91 | flags := command.Flags() |
| 92 | |
| 93 | if isRootCmd(command) { |
| 94 | if versionVal, err := flags.GetBool("version"); err == nil && versionVal { |
| 95 | fmt.Fprint(f.IOStreams.Out, command.Annotations["versionInfo"]) |
| 96 | return |
| 97 | } else if err != nil { |
| 98 | fmt.Fprintln(f.IOStreams.ErrOut, err) |
| 99 | hasFailed = true |
| 100 | return |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | cs := f.IOStreams.ColorScheme() |
| 105 | |
| 106 | if help, _ := flags.GetBool("help"); !help && !command.Runnable() && len(flags.Args()) > 0 { |
| 107 | nestedSuggestFunc(f.IOStreams.ErrOut, command, flags.Args()[0]) |
| 108 | hasFailed = true |
| 109 | return |
| 110 | } |
| 111 | |
| 112 | type helpEntry struct { |
| 113 | Title string |
| 114 | Body string |
| 115 | } |
| 116 | |
| 117 | longText := command.Long |
| 118 | if longText == "" { |
| 119 | longText = command.Short |
| 120 | } |
| 121 | if longText != "" && command.LocalFlags().Lookup("jq") != nil { |
| 122 | longText = strings.TrimRight(longText, "\n") + |
| 123 | "\n\nFor more information about output formatting flags, see `gh help formatting`." |
| 124 | } |
| 125 | |
| 126 | helpEntries := []helpEntry{} |
| 127 | if longText != "" { |
| 128 | helpEntries = append(helpEntries, helpEntry{"", longText}) |
| 129 | } |
| 130 | helpEntries = append(helpEntries, helpEntry{"USAGE", command.UseLine()}) |
| 131 | |
| 132 | if len(command.Aliases) > 0 { |
| 133 | helpEntries = append(helpEntries, helpEntry{"ALIASES", strings.Join(BuildAliasList(command, command.Aliases), ", ") + "\n"}) |
| 134 | } |
| 135 | |
| 136 | // Statically calculated padding for non-extension commands, |
| 137 | // longest is `gh accessibility` with 13 characters + 1 space. |
| 138 | // |
| 139 | // Should consider novel way to calculate this in the future [AF] |
| 140 | namePadding := 14 |
| 141 | |
| 142 | for _, g := range GroupedCommands(command) { |
| 143 | var names []string |
| 144 | for _, c := range g.Commands { |
| 145 | names = append(names, rpad(c.Name()+":", namePadding)+c.Short) |
| 146 | } |
| 147 | helpEntries = append(helpEntries, helpEntry{ |
no test coverage detected