Skip to content

feat: add --json flag to all 16 async commands (STOPS-7492)#907

Merged
vjeeva merged 1 commit intomainfrom
feat/json-flag
Mar 31, 2026
Merged

feat: add --json flag to all 16 async commands (STOPS-7492)#907
vjeeva merged 1 commit intomainfrom
feat/json-flag

Conversation

@vjeeva
Copy link
Copy Markdown
Contributor

@vjeeva vjeeva commented Mar 31, 2026

Summary

  • Adds --json flag to every async CLI command (all 16 commands PGBaaS invokes) via a single change to helpers.py
  • When --json is passed: structured CommandResult JSON to stdout, logs to stderr only, no tabulate output
  • On error: structured JSON with error_type/message, exit code 1
  • Without --json: behavior is completely unchanged
  • Zero changes to individual command implementations

How it works

The --json flag is injected in add_command() and threaded through run_with_configs() as json_mode. When true, the results_callback (tabulate/styled output) is skipped and _build_json_output() normalises the raw command results into a CommandResult JSON string:

  • None results (setup, teardown, etc.) → empty detail
  • Single dict (status, connectivity for one db) → dict becomes detail
  • Multiple dicts (DC-wide runs) → {"databases": [...]}

Test plan

  • pytest tests/pgbelt/ — 33 tests pass (6 new for JSON flag)
  • --json appears in --help for all async commands
  • --json coexists with command-specific options (--stride, --exclude-user, --schema, etc.)
  • CI passes

Made with Cursor

Wire --json into the CLI via helpers.py so every async command gets
structured JSON output without touching individual command files.

When --json is passed:
- results_callback is skipped (no tabulate/styled output)
- CommandResult.model_dump_json() is printed to stdout
- Logs continue to stderr (already the default via StreamHandler)
- Errors produce structured JSON with error_type/message, exit 1

Commands return their existing dicts/None; _build_json_output in
helpers.py normalises them into CommandResult. Richer per-item models
from STOPS-7491 can be wired in incrementally.

Made-with: Cursor
@vjeeva vjeeva merged commit c1770ab into main Mar 31, 2026
15 checks passed
@vjeeva vjeeva deleted the feat/json-flag branch March 31, 2026 18:51
@github-actions github-actions bot locked and limited conversation to collaborators Mar 31, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant