MCPcopy Create free account
hub / github.com/cli/cli / GroupedCommands

Function GroupedCommands

pkg/cmd/root/help.go:260–296  ·  view source on GitHub ↗
(cmd *cobra.Command)

Source from the content-addressed store, hash-verified

258}
259
260func GroupedCommands(cmd *cobra.Command) []CommandGroup {
261 var res []CommandGroup
262
263 for _, g := range cmd.Groups() {
264 var cmds []*cobra.Command
265 for _, c := range cmd.Commands() {
266 if c.GroupID == g.ID && c.IsAvailableCommand() {
267 cmds = append(cmds, c)
268 }
269 }
270 if len(cmds) > 0 {
271 res = append(res, CommandGroup{
272 Title: g.Title,
273 Commands: cmds,
274 })
275 }
276 }
277
278 var cmds []*cobra.Command
279 for _, c := range cmd.Commands() {
280 if c.GroupID == "" && c.IsAvailableCommand() {
281 cmds = append(cmds, c)
282 }
283 }
284 if len(cmds) > 0 {
285 defaultGroupTitle := "Additional commands"
286 if len(cmd.Groups()) == 0 {
287 defaultGroupTitle = "Available commands"
288 }
289 res = append(res, CommandGroup{
290 Title: defaultGroupTitle,
291 Commands: cmds,
292 })
293 }
294
295 return res
296}
297
298// rpad adds padding to the right of a string.
299func rpad(s string, padding int) string {

Callers 3

genMarkdownCustomFunction · 0.92
genManFunction · 0.92
WriteHelpFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected