Skip to content

feat(cli): add --json output to register, content, and pop commands#74

Closed
EnderOfWorlds007 wants to merge 1 commit into
paritytech:mainfrom
EnderOfWorlds007:feat/json-output-all-commands
Closed

feat(cli): add --json output to register, content, and pop commands#74
EnderOfWorlds007 wants to merge 1 commit into
paritytech:mainfrom
EnderOfWorlds007:feat/json-output-all-commands

Conversation

@EnderOfWorlds007
Copy link
Copy Markdown
Contributor

Summary

  • Add --json flag to register domain, register subname, content set, content view, pop set, and pop info commands
  • Follows the exact pattern already used by bulletin and lookup commands: maybeQuiet() suppresses human-readable output, structured JSON is written to stdout, errors go to stderr
  • The underlying viewDomainContentHash and setDomainContentHash functions now return result objects (backward compatible -- callers that ignored the void return still work)
  • Registration functions (executeRegistration, executeSubnameRegistration) now return result objects with label, domain, and owner

Motivation

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

Command stdout
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

  • Verify dotns register domain --json suppresses human output and prints JSON to stdout
  • Verify dotns content view <name> --json returns content hash or null
  • Verify dotns pop info --json returns status object
  • Verify error cases with --json write to stderr
  • Verify all commands without --json behave identically to before (no regressions)

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.
@andrew-ifrita
Copy link
Copy Markdown
Collaborator

Taking a quick look at the surface level.

contentHash.ts still logs to console even when --json is active. We will want to fix that. We should double check any stdout that happens when --json is active.

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

@sphamjoli
Copy link
Copy Markdown
Member

@EnderOfWorlds007 Very cool, please ensure you add tests at the various levels which ensures this PR doesnt introduce indirection for other features

Copy link
Copy Markdown
Member

@sphamjoli sphamjoli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see comment above

@EnderOfWorlds007
Copy link
Copy Markdown
Contributor Author

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:

  • 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's active lifecycle runs inside the maybeQuiet callback.
  • Added unit tests (8 tests): --json flag in help output, JSON error formatting for pre-chain validation errors (conflicting auth options, missing transfer destination).
  • Added integration tests (7 tests): content view --json, content set --json, content view --json (unregistered domain), content set --json (error path), pop info --json, pop set --json, register domain --json.

EnderOfWorlds007 added a commit that referenced this pull request Apr 16, 2026
)

## 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)
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.

3 participants