Skip to content

feat: add structured JSON output for all CLI commands#1517

Open
radu-mocanu wants to merge 1 commit intomainfrom
feat/768-cli-json-output
Open

feat: add structured JSON output for all CLI commands#1517
radu-mocanu wants to merge 1 commit intomainfrom
feat/768-cli-json-output

Conversation

@radu-mocanu
Copy link
Collaborator

@radu-mocanu radu-mocanu commented Mar 26, 2026

Summary

  • Rename ConsoleLoggerCliLogger with output_mode property ("console" | "json")
  • In JSON mode, all console.* methods collect messages internally instead of printing; console.error() raises CLIError instead of calling ctx.exit(1); spinners are suppressed
  • LazyGroup.invoke() wraps all command execution — calls CliLogger.emit() on success (JSON to stdout), catches CLIError/click.ClickException and emits JSON error to stderr
  • service_command decorator routes data through CliLogger.set_result() in JSON mode
  • Backwards-compatible: ConsoleLogger alias preserved, --format table (default) behavior unchanged

JSON Output Structure

Success:

{
  "status": "success",
  "messages": [{"level": "info", "message": "..."}],
  "data": { ... }
}

Error (stderr):

{
  "status": "error",
  "error": "Authentication failed...",
  "messages": [{"level": "info", "message": "..."}]
}

Test plan

  • 33 unit tests for CliLogger (console mode + JSON mode behavior)
  • 6 integration tests exercising full CLI flow with --format json
  • All 1696 existing tests pass (no regressions)
  • Lint and format clean (ruff check + ruff format)

Fixes #768

🤖 Generated with Claude Code

Development Packages

uipath

[project]
dependencies = [
  # Exact version:
  "uipath==2.10.34.dev1015175702",

  # Any version from PR
  "uipath>=2.10.34.dev1015170000,<2.10.34.dev1015180000"
]

[[tool.uv.index]]
name = "testpypi"
url = "https://test.pypi.org/simple/"
publish-url = "https://test.pypi.org/legacy/"
explicit = true

[tool.uv.sources]
uipath = { index = "testpypi" }

Rename ConsoleLogger to CliLogger with output_mode support.
When --format json is used, all console output is collected
internally and emitted as structured JSON at command exit.
Errors are caught by LazyGroup.invoke() and emitted as JSON
to stderr.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@github-actions github-actions bot added test:uipath-langchain Triggers tests in the uipath-langchain-python repository test:uipath-llamaindex Triggers tests in the uipath-llamaindex-python repository labels Mar 26, 2026
@radu-mocanu radu-mocanu added the build:dev Create a dev build from the pr label Mar 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build:dev Create a dev build from the pr test:uipath-langchain Triggers tests in the uipath-langchain-python repository test:uipath-llamaindex Triggers tests in the uipath-llamaindex-python repository

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for JSON output in CLI commands

1 participant