Skip to content

Commit

Permalink
Merge pull request #66 from dims/add-csv-option
Browse files Browse the repository at this point in the history
Add a CSV option as well
  • Loading branch information
dims authored Nov 4, 2024
2 parents e951587 + b0d2ea5 commit 34e8a61
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion cmd/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (

var dir string
var jsonOutput bool
var csvOutput bool
var verbose bool
var mainModules []string

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

if !jsonOutput {
if !jsonOutput && !csvOutput {
fmt.Printf("Direct Dependencies: %d \n", directDeps)
fmt.Printf("Transitive Dependencies: %d \n", transitiveDeps)
fmt.Printf("Total Dependencies: %d \n", totalDeps)
Expand Down Expand Up @@ -92,6 +93,10 @@ var statsCmd = &cobra.Command{
}
fmt.Print(string(outputRaw))
}
if csvOutput {
fmt.Println("Direct,Transitive,Total,MaxDepth")
fmt.Printf("%d,%d,%d,%d\n", directDeps, transitiveDeps, totalDeps, maxDepth)
}
return nil
},
}
Expand Down Expand Up @@ -137,5 +142,6 @@ func init() {
statsCmd.Flags().StringVarP(&dir, "dir", "d", "", "Directory containing the module to evaluate. Defaults to the current directory.")
statsCmd.Flags().BoolVarP(&verbose, "verbose", "v", false, "Get additional details")
statsCmd.Flags().BoolVarP(&jsonOutput, "json", "j", false, "Get the output in JSON format")
statsCmd.Flags().BoolVarP(&csvOutput, "csv", "c", false, "Get the output in CSV format")
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")
}

0 comments on commit 34e8a61

Please sign in to comment.