cli: add --json structured-output mode#885
Draft
kcsongor wants to merge 2 commits into
Draft
Conversation
7b1c095 to
f271ba6
Compare
0ad1b81 to
44239cf
Compare
76f2c77 to
11bf414
Compare
…transfer-ownership
Adds a global --json flag (also activated by WL_NTT_JSON=1) that:
- Redirects console.log / .info / .warn / .debug and direct process.stdout
writes to stderr.
- Emits exactly one { ok, command, data } envelope on stdout from the
command's success path via emitResult().
Failure paths are intentionally unstructured: non-zero exit + stderr
message is the contract. Wrappers (scripts, parent processes) read the
trailing stdout line on exit code 0; treat anything else as failure.
Bun's console implementation doesn't always route through
process.stdout.write, so we override the console methods directly *and*
hijack process.stdout.write for transitive deps.
Lets parent processes consume the per-instance token_authority PDA without
text-scraping stdout. Same { ok, command, data } envelope shape as the
other --json-aware commands.
11bf414 to
68ca889
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a
--jsonflag (also activated byWL_NTT_JSON=1) to the NTT CLI commands that parent processes / scripts most often need to drive:ntt initntt add-chain(both the regular and--instance-ofmulti-tenant paths)ntt push(regular +--dangerously-transfer-ownership-in-one-step)ntt transfer-ownershipntt solana token-authorityIn
--jsonmode, every stdout write (including libraryconsole.logs and Bun's native console) is redirected to stderr. The only thing that lands on stdout is exactly one final{ ok: true, command, data }envelope emitted from the command's success path.Failure paths intentionally stay unstructured: non-zero exit + stderr message is the contract. Wrappers read the trailing stdout line on exit 0; treat anything else as failure.
Why draft, why this base
This stack technically doesn't depend on #875 — the
--jsonwork touches commands that exist independent of the multi-tenant changes. But it's easier to keep the branches stacked while #875 is in flight, since #875 is also under active development and rebasing the JSON work onto main and then again onto #875's eventual merge state is fiddly.Don't merge this until #875 is merged. Once #875 lands on main, I'll re-target this PR to main and lift draft.
Test plan
bun test src/__tests__/— full suite still passes (160 pass)src/__tests__/json-output.test.tscovers:--jsonflagWL_NTT_JSON=1env var--jsonntt init --json | jq .,ntt solana token-authority ... --json | jq .ntt add-chain/ntt push/ntt transfer-ownershipagainst a real deployment (deferred until solana: multi-tenant deployment #875 lands)