Skip to content

Commit f987231

Browse files
committed
feat: add csv for output support
1 parent 6e85bee commit f987231

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

cmd/api.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ var apiCmd = &cobra.Command{
8686
table.Render()
8787
}
8888

89+
writeCsv(counts)
90+
8991
if apiCmdConfig.RemovePackageNames != "" {
9092
dotContent = replacePackage(dotContent)
9193
}
@@ -95,6 +97,18 @@ var apiCmd = &cobra.Command{
9597
},
9698
}
9799

100+
func writeCsv(counts []api_domain2.CallAPI) {
101+
csvTable, tableString := cmd_util.NewCsv()
102+
csvTable.SetHeader([]string{"Size", "Method", "URI", "Caller"})
103+
104+
for _, v := range counts {
105+
csvTable.Append([]string{strconv.Itoa(v.Size), v.HTTPMethod, v.URI, replacePackage(v.Caller)})
106+
}
107+
csvTable.Render()
108+
109+
cmd_util.WriteToCocaFile("api.csv", tableString.String())
110+
}
111+
98112
func forceUpdateApi() {
99113
app := new(api.JavaApiApp)
100114
restApis = app.AnalysisPath(filepath.FromSlash(apiCmdConfig.Path), parsedDeps, identifiersMap, diMap)

cmd/cmd_util/coca_output.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package cmd_util
33
import (
44
"github.com/olekukonko/tablewriter"
55
"io"
6+
"strings"
67
)
78

89
func NewOutput(output io.Writer) *tablewriter.Table {
@@ -12,3 +13,14 @@ func NewOutput(output io.Writer) *tablewriter.Table {
1213
table.SetColWidth(80)
1314
return table
1415
}
16+
17+
func NewCsv() (*tablewriter.Table, *strings.Builder) {
18+
tableString := &strings.Builder{}
19+
table := tablewriter.NewWriter(tableString)
20+
table.SetBorders(tablewriter.Border{Left: false, Top: false, Right: false, Bottom: false})
21+
table.SetCenterSeparator("")
22+
table.SetRowSeparator("")
23+
table.SetColumnSeparator(",")
24+
table.SetColWidth(80)
25+
return table, tableString
26+
}

0 commit comments

Comments
 (0)