Skip to content

Commit

Permalink
cli: add --checks.pretty
Browse files Browse the repository at this point in the history
  • Loading branch information
bobheadxi committed May 8, 2020
1 parent 97f14df commit 344c4d9
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 16 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ regressions don't happen:

```sh
gobenchdata checks generate
gobenchdata checks eval [base benchmarks] [current benchmarks]
gobenchdata checks eval ${base benchmarks} ${current benchmarks} --checks.pretty
```

For more details on how to use checks, see the [pull request checks documentation](#pull-request-checks).
Expand Down
2 changes: 1 addition & 1 deletion doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Visualize the results:
Compare results:
gobenchdata checks generate # generates config file to define checks
gobenchdata checks eval base-benchmarks.json current-benchmarks.json
gobenchdata checks eval base-benchmarks.json current-benchmarks.json --checks.pretty
Learn more in the repository README: https://github.com/bobheadxi/gobenchdata
*/
Expand Down
35 changes: 21 additions & 14 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ var (
webIndexTitle = pflag.String("web.title", "gobenchdata web", "header <title> for 'gobenchdata web'")
webIndexHead = pflag.StringArray("web.head", []string{}, "additional <head> elements for 'gobenchdata web'")

checksPretty = pflag.Bool("checks.pretty", false, "output report as human-readable format instead of JSON")
checksConfigPath = pflag.String("checks.config", "gobenchdata-checks.yml", "path to checks configuraton file")

version = pflag.StringP("version", "v", "", "version to tag in your benchmark output")
Expand Down Expand Up @@ -171,23 +172,27 @@ func main() {
if err != nil {
panic(err)
}

var b []byte
if *flat {
b, err = json.Marshal(res)
} else {
b, err = json.MarshalIndent(res, "", " ")
}
if err != nil {
panic(err)
}

if *jsonOut == "" {
println(string(b))
if *checksPretty {
outputChecksReport(res)
} else {
if err := ioutil.WriteFile(*jsonOut, b, os.ModePerm); err != nil {
var b []byte
if *flat {
b, err = json.Marshal(res)
} else {
b, err = json.MarshalIndent(res, "", " ")
}
if err != nil {
panic(err)
}

if *jsonOut == "" {
println(string(b))
} else {
if err := ioutil.WriteFile(*jsonOut, b, os.ModePerm); err != nil {
panic(err)
}
fmt.Printf("report output written to %s\n", *jsonOut)
}
}
case "report":
if len(pflag.Args()) < 3 {
Expand All @@ -198,6 +203,8 @@ func main() {
panic(err)
}
outputChecksReport(results)

// exit with code corresponding to status
if results.Status != checks.StatusPass {
os.Exit(1)
}
Expand Down

0 comments on commit 344c4d9

Please sign in to comment.