feat: add --json flag to all 16 async commands (STOPS-7492)#907
Merged
Conversation
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
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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
--jsonflag to every async CLI command (all 16 commands PGBaaS invokes) via a single change tohelpers.py--jsonis passed: structuredCommandResultJSON to stdout, logs to stderr only, no tabulate outputerror_type/message, exit code 1--json: behavior is completely unchangedHow it works
The
--jsonflag is injected inadd_command()and threaded throughrun_with_configs()asjson_mode. When true, theresults_callback(tabulate/styled output) is skipped and_build_json_output()normalises the raw command results into aCommandResultJSON string:Noneresults (setup, teardown, etc.) → emptydetaildetail{"databases": [...]}Test plan
pytest tests/pgbelt/— 33 tests pass (6 new for JSON flag)--jsonappears in--helpfor all async commands--jsoncoexists with command-specific options (--stride, --exclude-user, --schema, etc.)Made with Cursor