MCPcopy Create free account
hub / github.com/alecthomas/kong / CommandTree

Method CommandTree

help.go:530–557  ·  view source on GitHub ↗

CommandTree creates a tree with the given node name as root and its children's arguments and sub commands as leaves.

(node *Node, prefix string)

Source from the content-addressed store, hash-verified

528
529// CommandTree creates a tree with the given node name as root and its children's arguments and sub commands as leaves.
530func (h *HelpOptions) CommandTree(node *Node, prefix string) (rows [][2]string) {
531 var nodeName string
532 switch node.Type {
533 default:
534 nodeName += prefix + node.Name
535 if len(node.Aliases) != 0 {
536 nodeName += fmt.Sprintf(" (%s)", strings.Join(node.Aliases, ","))
537 }
538 case ArgumentNode:
539 nodeName += prefix + "<" + node.Name + ">"
540 }
541 rows = append(rows, [2]string{nodeName, node.Help})
542 if h.Indenter == nil {
543 prefix = SpaceIndenter(prefix)
544 } else {
545 prefix = h.Indenter(prefix)
546 }
547 for _, arg := range node.Positional {
548 rows = append(rows, [2]string{prefix + arg.Summary(), arg.Help})
549 }
550 for _, subCmd := range node.Children {
551 if subCmd.Hidden {
552 continue
553 }
554 rows = append(rows, h.CommandTree(subCmd, prefix)...)
555 }
556 return
557}
558
559// SpaceIndenter adds a space indent to the given prefix.
560func SpaceIndenter(prefix string) string {

Callers 1

writeCommandTreeFunction · 0.80

Calls 2

SpaceIndenterFunction · 0.85
SummaryMethod · 0.45

Tested by

no test coverage detected