diff --git a/cmd/goreportcard-cli/main.go b/cmd/goreportcard-cli/main.go index db1785f..cb57c46 100644 --- a/cmd/goreportcard-cli/main.go +++ b/cmd/goreportcard-cli/main.go @@ -3,6 +3,7 @@ package main import ( "flag" "fmt" + "encoding/json" "log" "os" @@ -13,6 +14,7 @@ var ( dir = flag.String("d", ".", "Root directory of your Go application") verbose = flag.Bool("v", false, "Verbose output") th = flag.Float64("t", 0, "Threshold of failure command") + jsn = flag.Bool("j", false, "JSON output. The binary will always exit with code 0") ) func main() { @@ -23,6 +25,12 @@ func main() { log.Fatalf("Fatal error checking %s: %s", *dir, err.Error()) } + if *jsn { + marshalledResults, _ := json.Marshal(result) + fmt.Println(string(marshalledResults)) + os.Exit(0) + } + fmt.Printf("Grade: %s (%.1f%%)\n", result.Grade, result.Average*100) fmt.Printf("Files: %d\n", result.Files) fmt.Printf("Issues: %d\n", result.Issues)