mirror of
https://github.com/gojp/goreportcard.git
synced 2026-01-28 22:39:05 +08:00
Merge pull request #293 from SirWindfield/add_json_flag
add json flag to output results as json
This commit is contained in:
@@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"encoding/json"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
@@ -13,6 +14,7 @@ var (
|
|||||||
dir = flag.String("d", ".", "Root directory of your Go application")
|
dir = flag.String("d", ".", "Root directory of your Go application")
|
||||||
verbose = flag.Bool("v", false, "Verbose output")
|
verbose = flag.Bool("v", false, "Verbose output")
|
||||||
th = flag.Float64("t", 0, "Threshold of failure command")
|
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() {
|
func main() {
|
||||||
@@ -23,6 +25,12 @@ func main() {
|
|||||||
log.Fatalf("Fatal error checking %s: %s", *dir, err.Error())
|
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("Grade: %s (%.1f%%)\n", result.Grade, result.Average*100)
|
||||||
fmt.Printf("Files: %d\n", result.Files)
|
fmt.Printf("Files: %d\n", result.Files)
|
||||||
fmt.Printf("Issues: %d\n", result.Issues)
|
fmt.Printf("Issues: %d\n", result.Issues)
|
||||||
|
|||||||
Reference in New Issue
Block a user