Skip to content

chore: Improve --json support accross multiple commands#347

Merged
blainekasten merged 2 commits intonextfrom
blaine/dx-368-cleanup-json-output-implementation
Apr 29, 2026
Merged

chore: Improve --json support accross multiple commands#347
blainekasten merged 2 commits intonextfrom
blaine/dx-368-cleanup-json-output-implementation

Conversation

@blainekasten
Copy link
Copy Markdown
Contributor

Summary

Standardizes CLI JSON output on console.print_json(openapi_dumps(...).decode("utf-8")) so serialization matches the SDK (datetime, Pydantic, etc.) and stdout stays valid JSON for tooling like jq.

Changes

  • Consistency: Replaced ad hoc json.dumps, rich.print_json, and raw JSON strings with the shared openapi_dumps + console.print_json pattern across touched commands (files upload/check paths, fine-tuning list/cancel, endpoints & storage retrieve, evals retrieve JSON path, jig helpers).
  • Telemetry: telemetry status, enable, and disable accept the global --json flag and emit single JSON objects (telemetry status includes structured disabled/enabled + reason where relevant).
  • files retrieve-content: --json emits jq-friendly payloads: stdout-only (content or content_base64), output-only (id + path), or combined {content|content_base64, path} when both --stdout and --output are set so we never print two unrelated JSON documents on one invocation.
  • Jig: _print_cli_result and detach deploy summary use openapi_dumps; beta jig volumes describe prints human-readable fields without --json and full JSON with --json (replacing always-JSON behavior for the default path).
  • Tests: Relaxed retrieve-content stdout assertions for optional leading newline from the loading spinner; added test_telemetry_json_mode_pipes_to_jq.

Notes

  • openapi_dumps in _utils/_json.py remains the single JSON serializer for CLI output (no parallel “custom date” path).
  • Subprocess JSON/jq tests that hit a mock API base URL still require that environment in CI.

Closes DX-368 (or link the Linear issue).

@blainekasten blainekasten force-pushed the blaine/dx-368-cleanup-json-output-implementation branch 3 times, most recently from 5123ab7 to 5f5fcf3 Compare April 28, 2026 15:34
@blainekasten blainekasten force-pushed the blaine/dx-368-cleanup-json-output-implementation branch from 5f5fcf3 to 45fcff4 Compare April 28, 2026 17:15
@blainekasten blainekasten requested a review from zainhas April 28, 2026 17:22
os.makedirs(os.path.dirname(output) or ".", exist_ok=True)
has_extension = Path(output).suffix != ""
out_path = output if has_extension else f"{output}/{await get_filename(config.client, id)}"
response2 = await config.client.files.content(id=id)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

we're reading the file twice - once in response then again in response2?

can we just reuse the first read Path(out_path).write_bytes(raw)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch, the logic was misguided as the parameters are mutually exclusive

@blainekasten blainekasten merged commit 949bfa4 into next Apr 29, 2026
9 checks passed
@stainless-app stainless-app Bot mentioned this pull request Apr 29, 2026
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.

2 participants