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)
| 528 | |
| 529 | // CommandTree creates a tree with the given node name as root and its children's arguments and sub commands as leaves. |
| 530 | func (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. |
| 560 | func SpaceIndenter(prefix string) string { |
no test coverage detected