Conditions | 8 |
Total Lines | 40 |
Code Lines | 23 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | package tree |
||
24 | func (s ResultTreePrinter) Print(results []scan.Result, out io.Writer) { |
||
25 | sort.Slice(results, func(i, j int) bool { |
||
26 | return results[i].Target.Path < results[j].Target.Path |
||
27 | }) |
||
28 | |||
29 | root := gotree.New("/") |
||
30 | |||
31 | // TODO: improve efficiency |
||
32 | for _, r := range results { |
||
33 | currentBranch := root |
||
34 | |||
35 | parts := strings.Split(r.URL.Path, "/") |
||
36 | for _, p := range parts { |
||
37 | if len(p) == 0 { |
||
38 | continue |
||
39 | } |
||
40 | |||
41 | found := false |
||
42 | |||
43 | for _, item := range currentBranch.Items() { |
||
44 | if item.Text() != p { |
||
45 | continue |
||
46 | } |
||
47 | |||
48 | currentBranch = item |
||
49 | found = true |
||
50 | break |
||
51 | } |
||
52 | |||
53 | if found { |
||
54 | continue |
||
55 | } |
||
56 | |||
57 | newTree := gotree.New(p) |
||
58 | currentBranch.AddTree(newTree) |
||
59 | currentBranch = newTree |
||
60 | } |
||
61 | } |
||
62 | |||
63 | _, _ = fmt.Fprintln(out, root.Print()) |
||
64 | } |
||
65 |