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

Function buildTree

pkg/cmd/skills/preview/preview.go:501–525  ·  view source on GitHub ↗

buildTree constructs a tree structure from flat file paths.

(files []discovery.SkillFile)

Source from the content-addressed store, hash-verified

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

Callers 2

renderFileTreeFunction · 0.85

Calls 1

sortTreeFunction · 0.85

Tested by 1