Skip to content

Commit 56e97b1

Browse files
authored
Moved output format to table format (#39)
* Moved output format to table format Moved output format to table format * Fix ci lint
1 parent 40b0f57 commit 56e97b1

File tree

4 files changed

+45
-11
lines changed

4 files changed

+45
-11
lines changed

sourcecode-parser/go.mod

+2
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@ require github.com/smacker/go-tree-sitter v0.0.0-20240625050157-a31a98a7c0f6
66

77
require queryparser v0.0.0-00010101000000-000000000000
88

9+
require github.com/jedib0t/go-pretty/v6 v6.5.9 // indirect
10+
911
replace queryparser => ./queryparser

sourcecode-parser/go.sum

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
22
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
33
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
4+
github.com/jedib0t/go-pretty/v6 v6.5.9 h1:ACteMBRrrmm1gMsXe9PSTOClQ63IXDUt03H5U+UV8OU=
5+
github.com/jedib0t/go-pretty/v6 v6.5.9/go.mod h1:zbn98qrYlh95FIhwwsbIip0LYpwSG8SUOScs+v9/t0E=
46
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
57
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
68
github.com/smacker/go-tree-sitter v0.0.0-20240423010953-8ba036550382 h1:Cb8njhEbNgGk5lQMM/r1FWvrKT+ysH8H0WV9NAIKAu8=
@@ -12,6 +14,7 @@ github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSS
1214
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
1315
github.com/stretchr/testify v1.7.4 h1:wZRexSlwd7ZXfKINDLsO4r7WBt3gTKONc6K/VesHvHM=
1416
github.com/stretchr/testify v1.7.4/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
17+
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
1518
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
1619
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
1720
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=

sourcecode-parser/go.work.sum

+15
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,17 @@
1+
github.com/felixge/fgprof v0.9.3 h1:VvyZxILNuCiUCSXtPtYmmtGvb65nqXh2QFWc0Wpf2/g=
2+
github.com/felixge/fgprof v0.9.3/go.mod h1:RdbpDgzqYVh/T9fPELJyV7EYJuHB55UTEULNun8eiPw=
3+
github.com/google/pprof v0.0.0-20211214055906-6f57359322fd h1:1FjCyPC+syAzJ5/2S8fqdZK1R22vvA0J7JZKcuOIQ7Y=
4+
github.com/google/pprof v0.0.0-20211214055906-6f57359322fd/go.mod h1:KgnwoLYCZ8IQu3XUZ8Nc/bM9CCZFOyjUNOSygVozoDg=
5+
github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U=
6+
github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
7+
github.com/pkg/profile v1.7.0 h1:hnbDkaNWPCLMO9wGLdBFTIZvzDrDfBM2072E1S9gJkA=
8+
github.com/pkg/profile v1.7.0/go.mod h1:8Uer0jas47ZQMJ7VD+OHknK4YDY07LPUC6dEvqDjvNo=
9+
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
10+
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
111
github.com/stretchr/objx v0.4.0 h1:M2gUjqZET1qApGOWNSnZ49BAIMX4F/1plDv3+l31EJ4=
12+
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
13+
golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y=
14+
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
15+
golang.org/x/term v0.17.0 h1:mkTF7LCd6WGJNL3K1Ad7kwxNfYAW6a8a8QqtMblp/4U=
16+
golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk=
217
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=

sourcecode-parser/main.go

+25-11
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import (
88
"os"
99
"queryparser"
1010
"strings"
11+
12+
"github.com/jedib0t/go-pretty/v6/table"
1113
)
1214

1315
func processQuery(input string, graph *CodeGraph, output string) (string, error) {
@@ -27,16 +29,29 @@ func processQuery(input string, graph *CodeGraph, output string) (string, error)
2729
}
2830
return string(queryResults), nil
2931
}
30-
var result strings.Builder
31-
result.WriteString("------Query Results------\n")
32-
for _, entity := range entities {
33-
result.WriteString("-------------------\n")
34-
result.WriteString(entity.CodeSnippet + "\n")
35-
result.WriteString(entity.File + "\n")
36-
result.WriteString("-------------------\n")
32+
33+
t := table.NewWriter()
34+
t.SetOutputMirror(os.Stdout)
35+
t.AppendHeader(table.Row{"#", "File", "Line Number", "Type", "Name", "Code Snippet"})
36+
t.SetColumnConfigs([]table.ColumnConfig{
37+
{
38+
Name: "File",
39+
WidthMin: 6,
40+
WidthMax: 40,
41+
},
42+
{
43+
Name: "Code Snippet",
44+
WidthMin: 6,
45+
WidthMax: 60,
46+
},
47+
})
48+
for i, entity := range entities {
49+
t.AppendRow([]interface{}{i + 1, entity.File, entity.LineNumber, entity.Type, entity.Name, entity.CodeSnippet})
50+
t.AppendSeparator()
3751
}
38-
result.WriteString("-------------------\n")
39-
return result.String(), nil
52+
t.SetStyle(table.StyleLight)
53+
t.Render()
54+
return "", nil
4055
}
4156

4257
func executeProject(project, query, output string, stdin bool) (string, error) {
@@ -59,11 +74,10 @@ func executeProject(project, query, output string, stdin bool) (string, error) {
5974
if strings.HasPrefix(input, ":quit") {
6075
return "Okay, Bye!", nil
6176
}
62-
result, err := processQuery(input, graph, output)
77+
_, err = processQuery(input, graph, output)
6378
if err != nil {
6479
return "", fmt.Errorf("error processing query: %w", err)
6580
}
66-
fmt.Println(result)
6781
}
6882
} else if output != "" && query != "" {
6983
return processQuery(query, graph, output)

0 commit comments

Comments
 (0)