Skip to content

feat: zero fmt --write and --check --json envelope#46

Open
gke0op wants to merge 1 commit into
vercel-labs:mainfrom
gke0op:fmt-check-json
Open

feat: zero fmt --write and --check --json envelope#46
gke0op wants to merge 1 commit into
vercel-labs:mainfrom
gke0op:fmt-check-json

Conversation

@gke0op
Copy link
Copy Markdown

@gke0op gke0op commented May 17, 2026

Summary

Adds --write flag and --json envelope support to zero fmt, matching the contract of every other Zero command.

New features

  • zero fmt --write <file> overwrites the file in place
  • zero fmt --check --json emits structured envelope with ok and unformatted
  • zero fmt --write --json emits structured envelope with ok and written
  • --check and --write are mutually exclusive (error in both text and json modes)
  • Bare zero fmt still prints to stdout (backward compatible)

JSON envelope shape

{
  "schemaVersion": 1,
  "command": "fmt",
  "mode": "check",
  "sourceFile": "examples/hello.0",
  "ok": true
}

When unformatted:

{
  "schemaVersion": 1,
  "command": "fmt",
  "mode": "check",
  "sourceFile": "/tmp/messy.0",
  "ok": false,
  "unformatted": ["/tmp/messy.0"]
}

Changes

  • Added fmt_write field to Command struct
  • Added --write flag parsing
  • Added mutual exclusivity check for --check and --write
  • Added JSON envelope for --check mode (was previously ignored)
  • Added JSON envelope for --write mode
  • Updated help text (both summary and detailed)
  • Text mode behavior unchanged

Testing

All existing tests pass (9 CLI, 8 docs, command contracts).

Manual verification:

  • zero fmt --check examples/hello.0 → exit 0
  • zero fmt --check /tmp/messy.0 → exit 1 with "format differs"
  • zero fmt --check --json /tmp/messy.0 → envelope with ok:false, exit 1
  • zero fmt --write /tmp/messy.0 → rewrites file, prints "formatted: "
  • zero fmt --write --json /tmp/messy.0 → envelope with ok:true
  • zero fmt --check --write file.0 → mutual exclusivity error
  • zero fmt file.0 → still prints to stdout (backward compat)
  • Formatted output is idempotent (fmt → check → ok)

Closes #9

Adds --write flag and --json envelope support to zero fmt, matching
the contract of every other Zero command.

New features:
- zero fmt --write <file> overwrites the file in place
- zero fmt --check --json emits { schemaVersion, command, mode, sourceFile, ok, unformatted }
- zero fmt --write --json emits { schemaVersion, command, mode, sourceFile, ok, written }
- --check and --write are mutually exclusive (error in both text and json modes)
- Bare zero fmt still prints to stdout (backward compat)

Text mode for --check is unchanged (fmt ok / format differs).

Closes vercel-labs#9
@vercel
Copy link
Copy Markdown

vercel Bot commented May 17, 2026

@gke0op is attempting to deploy a commit to the Vercel Labs Team on Vercel.

A member of the Team first needs to authorize it.

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