Skip to content

Commit 34e8a61

Browse files
authored
Merge pull request #66 from dims/add-csv-option
Add a CSV option as well
2 parents e951587 + b0d2ea5 commit 34e8a61

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

cmd/stats.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525

2626
var dir string
2727
var jsonOutput bool
28+
var csvOutput bool
2829
var verbose bool
2930
var mainModules []string
3031

@@ -55,7 +56,7 @@ var statsCmd = &cobra.Command{
5556
transitiveDeps := len(depGraph.TransDepList)
5657
totalDeps := len(getAllDeps(depGraph.DirectDepList, depGraph.TransDepList))
5758

58-
if !jsonOutput {
59+
if !jsonOutput && !csvOutput {
5960
fmt.Printf("Direct Dependencies: %d \n", directDeps)
6061
fmt.Printf("Transitive Dependencies: %d \n", transitiveDeps)
6162
fmt.Printf("Total Dependencies: %d \n", totalDeps)
@@ -92,6 +93,10 @@ var statsCmd = &cobra.Command{
9293
}
9394
fmt.Print(string(outputRaw))
9495
}
96+
if csvOutput {
97+
fmt.Println("Direct,Transitive,Total,MaxDepth")
98+
fmt.Printf("%d,%d,%d,%d\n", directDeps, transitiveDeps, totalDeps, maxDepth)
99+
}
95100
return nil
96101
},
97102
}
@@ -137,5 +142,6 @@ func init() {
137142
statsCmd.Flags().StringVarP(&dir, "dir", "d", "", "Directory containing the module to evaluate. Defaults to the current directory.")
138143
statsCmd.Flags().BoolVarP(&verbose, "verbose", "v", false, "Get additional details")
139144
statsCmd.Flags().BoolVarP(&jsonOutput, "json", "j", false, "Get the output in JSON format")
145+
statsCmd.Flags().BoolVarP(&csvOutput, "csv", "c", false, "Get the output in CSV format")
140146
statsCmd.Flags().StringSliceVarP(&mainModules, "mainModules", "m", []string{}, "Enter modules whose dependencies should be considered direct dependencies; defaults to the first module encountered in `go mod graph` output")
141147
}

0 commit comments

Comments
 (0)