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