MCPcopy Index your code
hub / github.com/cli/cli / buildTree

Function buildTree

pkg/cmd/skills/preview/preview.go:500–524  ·  view source on GitHub ↗

buildTree constructs a tree structure from flat file paths.

(files []discovery.SkillFile)

Source from the content-addressed store, hash-verified

498
499// buildTree constructs a tree structure from flat file paths.
500func buildTree(files []discovery.SkillFile) *treeNode {
501 root := &treeNode{isDir: true}
502 for _, f := range files {
503 parts := strings.Split(f.Path, "/")
504 current := root
505 for i, part := range parts {
506 isLast := i == len(parts)-1
507 found := false
508 for _, child := range current.children {
509 if child.name == part {
510 current = child
511 found = true
512 break
513 }
514 }
515 if !found {
516 node := &treeNode{name: part, isDir: !isLast}
517 current.children = append(current.children, node)
518 current = node
519 }
520 }
521 }
522 sortTree(root)
523 return root
524}
525
526func sortTree(node *treeNode) {
527 sort.Slice(node.children, func(i, j int) bool {

Callers 2

renderFileTreeFunction · 0.85

Calls 1

sortTreeFunction · 0.85

Tested by 1