-
Notifications
You must be signed in to change notification settings - Fork 37
fix(ceng-630): Fix JSON output across all commands #248
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR significantly improves JSON output handling across the Cloudsmith CLI by ensuring that when --output-format json is used, all informational messages, warnings, and prompts are sent to stderr, while structured JSON results and errors are sent to stdout. This enables clean, machine-readable JSON output that can be easily parsed by shell scripts and automation tools.
Key changes include:
- Introduction of utility functions (
should_use_stderr,get_output_format,maybe_print_status_json) to standardize JSON output detection - Comprehensive update of exception handling to format API errors as structured JSON
- Implementation of Click exception interception to format usage errors as JSON
- Systematic addition of
err=use_stderrparameters to all informational messages across commands - Addition of JSON output support to commands that previously only had text output
- Deprecation of the
--jsonflag in theauthcommand in favor of--output-format json
Reviewed changes
Copilot reviewed 31 out of 31 changed files in this pull request and generated 13 comments.
Show a summary per file
| File | Description |
|---|---|
| cloudsmith_cli/cli/utils.py | Added utility functions for JSON output detection and stderr routing |
| cloudsmith_cli/cli/exceptions.py | Enhanced API exception handler to output structured JSON errors with proper field handling |
| cloudsmith_cli/cli/command.py | Added Click exception interception to format usage errors as JSON |
| cloudsmith_cli/cli/webserver.py | Updated 2FA prompt to use stderr when appropriate |
| cloudsmith_cli/cli/commands/whoami.py | Updated to route informational messages to stderr and use utility functions |
| cloudsmith_cli/cli/commands/upstream.py | Applied stderr routing for informational messages and confirmation prompts |
| cloudsmith_cli/cli/commands/tokens.py | Updated token operations to use stderr routing and handle deprecated json flag |
| cloudsmith_cli/cli/commands/tags.py | Applied stderr routing for all tag operation messages |
| cloudsmith_cli/cli/commands/status.py | Added JSON output support for package status with stderr routing |
| cloudsmith_cli/cli/commands/resync.py | Added JSON output support for resync operations with stderr routing |
| cloudsmith_cli/cli/commands/repos.py | Updated repository operations to use stderr routing utility |
| cloudsmith_cli/cli/commands/quota/*.py | Applied stderr routing for quota usage commands |
| cloudsmith_cli/cli/commands/quarantine.py | Added JSON output support for quarantine operations with stderr routing |
| cloudsmith_cli/cli/commands/push.py | Significant changes to handle progress bars, add JSON output for push results, and route all informational output to stderr |
| cloudsmith_cli/cli/commands/policy/*.py | Applied stderr routing for policy management commands |
| cloudsmith_cli/cli/commands/move.py | Added JSON output support for move operations with stderr routing |
| cloudsmith_cli/cli/commands/metrics/*.py | Updated metrics commands to use stderr routing utility |
| cloudsmith_cli/cli/commands/login.py | Added JSON output support and stderr routing for login command |
| cloudsmith_cli/cli/commands/list_.py | Applied stderr routing for list commands |
| cloudsmith_cli/cli/commands/entitlements.py | Updated entitlement operations to use stderr routing utility |
| cloudsmith_cli/cli/commands/download.py | Applied stderr routing for download progress messages |
| cloudsmith_cli/cli/commands/dependencies.py | Applied stderr routing for dependency listing |
| cloudsmith_cli/cli/commands/delete.py | Added JSON output support for delete operations with stderr routing |
| cloudsmith_cli/cli/commands/copy.py | Added JSON output support for copy operations with stderr routing |
| cloudsmith_cli/cli/commands/check.py | Added JSON output support for service and rate limit checks with stderr routing |
| cloudsmith_cli/cli/commands/auth.py | Updated authentication to handle deprecated json flag and use stderr routing |
| CHANGELOG.md | Added deprecation notice and fixed section for JSON output improvements |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 31 out of 31 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This pull request significantly improves the Cloudsmith CLI's handling of output when the
--output-format jsonoption is used. It ensures that all informational messages, warnings, and prompts are sent to stderr, while error messages from command results are properly formatted as structured JSON on stdout. The changes will also output click exceptions in JSON format to ensure consistent results being returned when things fail.The most important changes are:
Deprecation warning:
--jsonparameter used as part of thecloudsmith authcommand will be removed in a future release of the CLI. Users are asked to switch back to using--output-format jsonstarting from this release.Output Handling and JSON Support:
--output-format jsonis active, and output error messages as structured JSON on stdout. This ensures clean and machine-readable JSON output for all commands.utils.should_use_stderr(opts)utility function across all commands to determine when to send output to stderr, replacing previous ad-hoc checks.Command Updates:
auth,check,copy,delete,download,entitlements,list_, andloginto use the new stderr logic for informational and prompt messages, and to output results/errors as JSON when requested.Examples:
Shell redirect will hide all output and present only the result in JSON:
Example download command:
Error example (Note the information message is coming from stderr so the JSON is left intact and parasable)
Click error example:
JSON Error Schema: