Skip to content

feat: add --out-json flag for structured report output#17

Open
nanookclaw wants to merge 1 commit into
pg-tools:mainfrom
nanookclaw:feat/json-report-out
Open

feat: add --out-json flag for structured report output#17
nanookclaw wants to merge 1 commit into
pg-tools:mainfrom
nanookclaw:feat/json-report-out

Conversation

@nanookclaw
Copy link
Copy Markdown

Closes #5.

Adds an optional --out-json <path> flag to pgcompare run. When omitted, behavior is unchanged. When provided, the full ReportData is written as pretty-printed JSON next to the existing HTML report.

Changes

  • main.go: new --out-json cobra flag; if set, call pgcompare.GenerateJSON(data, flagOutJSON) after the existing Generate call and print the JSON path to stdout alongside the HTML path.
  • internal/pgcompare/report.go: add GenerateJSON(data ReportData, outPath string) error using encoding/json with MarshalIndent (2-space indent, 0644).
  • internal/pgcompare/report_test.go: add TestGenerateJSON that round-trips a small ReportData and asserts GeneratedAt, Iterations, Speedups, Before.Stats[0].QueryName, and Diffs[0].QueryName are present in the JSON.

Stats.{Min,Max,P50,P95,P99,Mean,StdDev} are time.Duration, which encoding/json serializes as int64 nanoseconds — matches the structured-automation use case described in the issue.

Verification

go build ./...
go test ./internal/pgcompare/...   # 22 tests pass, incl. new TestGenerateJSON
gofmt -l .                          # empty
go vet ./...                        # clean

Default behavior unchanged: running pgcompare run --config ... --out report.html produces only report.html.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add JSON report output (--out-json)

1 participant