feat: zero fmt --write and --check --json envelope#46
Conversation
|
@gke0op is attempting to deploy a commit to the Vercel Labs Team on Vercel. A member of the Team first needs to authorize it. |
|
@mvanhorn — I see your #9 covers the same Rather than compete, want to coordinate? Options:
Either way, let's not duplicate effort. What do you prefer? |
Rebase complete ✅Rebased onto latest origin/main (v0.1.2, post borrow-provenance + HTTP client merge). All conflicts resolved. Each branch now has a clean linear history on top of current main. |
|
Rebased onto latest origin/main (v0.1.2). All conflicts resolved. Clean linear history. |
| } | ||
| if (command.fmt_write) { | ||
| ZDiag write_diag = {0}; | ||
| bool written = z_write_file(fmt_input.source_file, formatted, &write_diag); |
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
|
Thanks for the detailed offer to coordinate. I read both diffs - #46's two real wins over #9 are the Would option 1 work for you? Close #46 and either:
#9 also has the docs update and a defensive null-check on |
Summary
Adds
--writeflag and--jsonenvelope support tozero fmt, matching the contract of every other Zero command.New features
zero fmt --write <file>overwrites the file in placezero fmt --check --jsonemits structured envelope withokandunformattedzero fmt --write --jsonemits structured envelope withokandwritten--checkand--writeare mutually exclusive (error in both text and json modes)zero fmtstill 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
fmt_writefield toCommandstruct--writeflag parsing--checkand--write--checkmode (was previously ignored)--writemodeTesting
All existing tests pass (9 CLI, 8 docs, command contracts).
Manual verification:
zero fmt --check examples/hello.0→ exit 0zero fmt --check /tmp/messy.0→ exit 1 with "format differs"zero fmt --check --json /tmp/messy.0→ envelope with ok:false, exit 1zero fmt --write /tmp/messy.0→ rewrites file, prints "formatted: "zero fmt --write --json /tmp/messy.0→ envelope with ok:truezero fmt --check --write file.0→ mutual exclusivity errorzero fmt file.0→ still prints to stdout (backward compat)Closes #9