Skip to content

Commit

Permalink
feat: add csv for output support
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Jul 5, 2021
1 parent 6e85bee commit f987231
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
14 changes: 14 additions & 0 deletions cmd/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ var apiCmd = &cobra.Command{
table.Render()
}

writeCsv(counts)

if apiCmdConfig.RemovePackageNames != "" {
dotContent = replacePackage(dotContent)
}
Expand All @@ -95,6 +97,18 @@ var apiCmd = &cobra.Command{
},
}

func writeCsv(counts []api_domain2.CallAPI) {
csvTable, tableString := cmd_util.NewCsv()
csvTable.SetHeader([]string{"Size", "Method", "URI", "Caller"})

for _, v := range counts {
csvTable.Append([]string{strconv.Itoa(v.Size), v.HTTPMethod, v.URI, replacePackage(v.Caller)})
}
csvTable.Render()

cmd_util.WriteToCocaFile("api.csv", tableString.String())
}

func forceUpdateApi() {
app := new(api.JavaApiApp)
restApis = app.AnalysisPath(filepath.FromSlash(apiCmdConfig.Path), parsedDeps, identifiersMap, diMap)
Expand Down
12 changes: 12 additions & 0 deletions cmd/cmd_util/coca_output.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd_util
import (
"github.com/olekukonko/tablewriter"
"io"
"strings"
)

func NewOutput(output io.Writer) *tablewriter.Table {
Expand All @@ -12,3 +13,14 @@ func NewOutput(output io.Writer) *tablewriter.Table {
table.SetColWidth(80)
return table
}

func NewCsv() (*tablewriter.Table, *strings.Builder) {
tableString := &strings.Builder{}
table := tablewriter.NewWriter(tableString)
table.SetBorders(tablewriter.Border{Left: false, Top: false, Right: false, Bottom: false})
table.SetCenterSeparator("")
table.SetRowSeparator("")
table.SetColumnSeparator(",")
table.SetColWidth(80)
return table, tableString
}

0 comments on commit f987231

Please sign in to comment.