summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorFlu0r1ne <flur01ne@flu0r1ne.net>2021-09-05 13:52:39 -0500
committerFlu0r1ne <flur01ne@flu0r1ne.net>2021-09-05 13:57:16 -0500
commit6876ea1e5cc3319b0d23d829a14f83b9a55663d2 (patch)
tree7892c8aecb9254e8238eddde6ed4c499652c9342 /cmd
parent54276b73eacfab6a5d6b899bd638f6cfe9499b80 (diff)
downloaddeb-planr-6876ea1e5cc3319b0d23d829a14f83b9a55663d2.tar.xz
deb-planr-6876ea1e5cc3319b0d23d829a14f83b9a55663d2.zip
Add flag for JSON eval output
Diffstat (limited to 'cmd')
-rw-r--r--cmd/planr/main.go1
-rw-r--r--cmd/planr/sub/evaluate.go52
2 files changed, 45 insertions, 8 deletions
diff --git a/cmd/planr/main.go b/cmd/planr/main.go
index d250bbd..b073115 100644
--- a/cmd/planr/main.go
+++ b/cmd/planr/main.go
@@ -19,6 +19,7 @@ func printUsage(w io.Writer) {
fmt.Fprintln(w, " version ")
fmt.Fprintln(w, " build ")
fmt.Fprintln(w, " evaluate ")
+ fmt.Fprintln(w, " evaluate -json ")
fmt.Fprintln(w, " clean ")
fmt.Fprintln(w, " config ")
}
diff --git a/cmd/planr/sub/evaluate.go b/cmd/planr/sub/evaluate.go
index 81c9989..95f88d0 100644
--- a/cmd/planr/sub/evaluate.go
+++ b/cmd/planr/sub/evaluate.go
@@ -1,21 +1,57 @@
package sub
import (
- "golang.flu0r1ne.net/planr"
+ "encoding/json"
+ "fmt"
+ "log"
+ "flag"
+
+ "golang.flu0r1ne.net/planr"
)
+type gradingResults struct {
+ TestResults []planr.TestResult
+ Score planr.Scoring
+}
+
+func prettyPrint(results gradingResults) {
+ for _, tr := range results.TestResults {
+ tcPprint(tr)
+ }
+
+ printScoring(results.Score)
+}
+
+func jsonPrint(results gradingResults) {
+ res, err := json.Marshal(results)
+
+ if err != nil {
+ log.Fatalf("Error printing JSON: %v\n", err)
+ }
+
+ fmt.Println(string(res))
+}
func Evaluate(runner planr.Runner, params []string, cfg planr.Config) {
+ f := flag.NewFlagSet("evaluate", flag.ExitOnError)
+
+ jsonOutput := f.Bool("json", false, "print json output")
+
+ f.Parse(params)
+
dieIncompatibleVersion(cfg)
tcs := runner.CollectCases()
trs := runner.Evaluate(tcs)
-
- score := planr.Score(trs)
-
- for _, tr := range trs {
- tcPprint(tr)
+
+ results := gradingResults {
+ TestResults: trs,
+ Score: planr.Score(trs),
+ }
+
+ if *jsonOutput {
+ jsonPrint(results)
+ } else {
+ prettyPrint(results)
}
-
- printScoring(score)
}