Skip to content

Add sp doctor --json output for scripting - #21

Merged
rwrife merged 1 commit into
mainfrom
issue-6-doctor-json
Jul 5, 2026
Merged

Add sp doctor --json output for scripting#21
rwrife merged 1 commit into
mainfrom
issue-6-doctor-json

Conversation

@rwrife

@rwrife rwrife commented Jul 4, 2026

Copy link
Copy Markdown
Owner

Advances #6 (M6 acceptance: "--json output mode for ls (and other read commands) for scripting").

sp ls already had --json; sp doctor produces the richest structured data in the tool (health flag, counts, footprint, orphan/missing drift) but had no machine-readable mode. This adds it.

What changed

  • internal/render/json.go — new DoctorJSON view + DoctorReportJSON(w, data) emitter. Mirrors the human report's information as pure data: top-level healthy flag, live/morgue counts, tracked/orphan/total sizes (raw bytes and human strings, matching the ls JSON convention), and orphans/missing arrays. Slices are always arrays, never null, so scripts can iterate unconditionally. Color- and personality-free, same contract as sp ls --json.
  • internal/cli/doctor.go--json flag routes to the JSON emitter and, like ls --json, never tints output regardless of TTY/--no-color.
  • Tests — render-layer unit tests (healthy + drift) and full-command CLI tests (doctor_json_test.go) asserting valid parseable JSON, colorless/flavor-free output, correct healthy flip, orphan/missing surfacing, and that the run stays read-only (orphan still on disk afterward).
  • Docs — README doctor section + quick-reference updated (sp doctor --json | jq -e '.healthy'); root.go package doc updated.

Example

{
  "healthy": false,
  "liveCount": 1,
  "morgueCount": 0,
  "trackedSize": 0, "trackedSizeHuman": "0B",
  "orphanSize": 5,  "orphanSizeHuman": "5B",
  "totalSize": 5,   "totalSizeHuman": "5B",
  "orphans": [ { "path": ".../scratches/cafef00d.md", "area": "scratches", "size": 5, "sizeHuman": "5B" } ],
  "missing": []
}

Verification

go build ./..., go vet ./..., go test ./... all green; go mod tidy clean; gofmt clean.

Not in scope (remaining M6)

Tagging/publishing v0.1.0 and pointing the README install section at the release are deliberately left out — the release workflow is tag-driven and a maintainer decision.

@rwrife rwrife mentioned this pull request Jul 4, 2026
7 tasks
@rwrife
rwrife merged commit f10c746 into main Jul 5, 2026
1 check passed
@rwrife
rwrife deleted the issue-6-doctor-json branch July 5, 2026 09:02
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.

1 participant