feat(cli): add --json output to register, content, and pop commands#74
feat(cli): add --json output to register, content, and pop commands#74EnderOfWorlds007 wants to merge 1 commit into
Conversation
Add structured JSON output support to all CLI commands that were missing it: register domain, register subname, content set, content view, pop set, and pop info. This follows the same pattern already used by the bulletin and lookup commands -- the --json flag suppresses human-readable output via maybeQuiet() and writes a single JSON line to stdout. The underlying contentHash functions now return result objects (domain, cid, contenthash, txHash) and the registration functions return result objects (label, domain, owner) so the CLI layer can serialize them. Errors are written as JSON to stderr when --json is active.
|
Taking a quick look at the surface level.
We will need automated tests in place as well. A simple happy path for the commands you mentioned should suffice. I see a lot of CI jobs failing because of "Resource not accessible by integration" which I think is a result of coming from a fork. Would you be able to push this straight to this project to clear those up? @EnderOfWorlds007 - from our side a longer term fix would be to have something in place where a maintainer can manually kick off the jobs |
|
@EnderOfWorlds007 Very cool, please ensure you add tests at the various levels which ensures this PR doesnt introduce indirection for other features |
|
Closing this fork PR and re-opening from an in-repo branch to fix CI permissions ("Resource not accessible by integration" on fork PRs). See the replacement PR linked below. Changes in the new PR on top of this one:
|
) ## Summary Adds `--json` flag to 6 commands that lacked it (`content view`, `content set`, `pop set`, `pop info`, `register domain`, `register subname`). The `bulletin` and `lookup` commands already had `--json`. Replaces #74 (fork PR → upstream branch to fix CI permissions). ### Changes from #74 - Switched JSON output from `process.stdout.write` to `console.log` (and `process.stderr.write` to `console.error`) to align with the existing `--json` pattern in `lookup.ts`. The test harness only intercepts `console.log`/`console.error`, so the previous approach wouldn't have been captured in tests. - Added code comment explaining why ora spinners are safe inside `maybeQuiet`: `withCapturedConsole` replaces `.write` on the `process.stderr` object, and ora caches the stream object reference (not the method), so spinner output is captured when the spinner lifecycle runs inside `maybeQuiet`. - Added unit tests (8 tests): `--json` flag in help output, JSON error formatting for pre-chain validation errors. - Added integration tests (7 tests): happy-path JSON output for all 6 commands plus error path for `content set`. ### JSON output shapes ``` dotns register domain -n <label> --json → { "ok": true, "label": "...", "domain": "....dot", "owner": "0x..." } dotns register subname -n <sub> -p <parent> --json → { "ok": true, "label": "...", "parent": "...", "domain": "sub.parent.dot", "owner": "0x..." } dotns content view <name> --json → { "domain": "....dot", "contenthash": "0x...", "cid": "bafy..." } dotns content set <name> <cid> --json → { "ok": true, "domain": "....dot", "cid": "bafy...", "contenthash": "0x...", "txHash": "0x..." } dotns pop set <status> --json → { "ok": true, "status": "full", "statusCode": 2 } dotns pop info --json → { "substrate": "5D...", "evm": "0x...", "status": "proofofpersonhoodfull", "statusCode": 2 } Errors (all commands): → stderr: { "error": "..." } → exit code 1 ``` ## Reviewer feedback addressed 1. **Console leak in contentHash.ts** — Verified that `withCapturedConsole` intercepts `process.stderr.write` (not just `console.log`), so ora spinner output is captured when `maybeQuiet` wraps the call scope. Added code comment explaining the mechanism. 2. **Automated tests** — Added 8 unit tests and 7 integration tests covering all `--json` commands. 3. **Push to upstream** — This PR comes from an in-repo branch, fixing the fork CI permissions issue. ## Test plan - [x] Unit tests pass: `bun test tests/unit/` (142 tests, 0 failures) - [ ] Integration tests pass against Paseo testnet - [ ] CI passes (no longer fork-blocked)
Summary
--jsonflag to register domain, register subname, content set, content view, pop set, and pop info commandsbulletinandlookupcommands:maybeQuiet()suppresses human-readable output, structured JSON is written to stdout, errors go to stderrviewDomainContentHashandsetDomainContentHashfunctions now return result objects (backward compatible -- callers that ignored thevoidreturn still work)executeRegistration,executeSubnameRegistration) now return result objects with label, domain, and ownerMotivation
Tools like bulletin-deploy need to programmatically parse CIDs, tx hashes, and status from CLI output. Without
--json, they must resort to fragile regex parsing of human-readable output that can break when formatting changes.JSON output shapes
register domain --json{"ok":true,"label":"...","domain":"...dot","owner":"0x..."}register subname --json{"ok":true,"label":"...","parent":"...","domain":"...dot","owner":"0x..."}content view --json{"domain":"...dot","contenthash":"0x...","cid":"..."}or{"domain":"...dot","contenthash":null,"cid":null}content set --json{"ok":true,"domain":"...dot","cid":"...","contenthash":"0x...","txHash":"0x..."}pop set --json{"ok":true,"status":"full","statusCode":2}pop info --json{"substrate":"...","evm":"0x...","status":"full","statusCode":2}On error with
--json, all commands write{"error":"..."}to stderr and exit non-zero.Test plan
dotns register domain --jsonsuppresses human output and prints JSON to stdoutdotns content view <name> --jsonreturns content hash or nulldotns pop info --jsonreturns status object--jsonwrite to stderr--jsonbehave identically to before (no regressions)