MCPcopy
hub / github.com/cli/cli / GroupedCommands

Function GroupedCommands

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

Source from the content-addressed store, hash-verified

243}
244
245func GroupedCommands(cmd *cobra.Command) []CommandGroup {
246 var res []CommandGroup
247
248 for _, g := range cmd.Groups() {
249 var cmds []*cobra.Command
250 for _, c := range cmd.Commands() {
251 if c.GroupID == g.ID && c.IsAvailableCommand() {
252 cmds = append(cmds, c)
253 }
254 }
255 if len(cmds) > 0 {
256 res = append(res, CommandGroup{
257 Title: g.Title,
258 Commands: cmds,
259 })
260 }
261 }
262
263 var cmds []*cobra.Command
264 for _, c := range cmd.Commands() {
265 if c.GroupID == "" && c.IsAvailableCommand() {
266 cmds = append(cmds, c)
267 }
268 }
269 if len(cmds) > 0 {
270 defaultGroupTitle := "Additional commands"
271 if len(cmd.Groups()) == 0 {
272 defaultGroupTitle = "Available commands"
273 }
274 res = append(res, CommandGroup{
275 Title: defaultGroupTitle,
276 Commands: cmds,
277 })
278 }
279
280 return res
281}
282
283// rpad adds padding to the right of a string.
284func rpad(s string, padding int) string {

Callers 3

genMarkdownCustomFunction · 0.92
genManFunction · 0.92
rootHelpFuncFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected