Skip to content

Add --output json to flow ls, work-pool ls, task-run ls, concurrency-limit ls#20904

Open
h1whelan wants to merge 1 commit intoPrefectHQ:mainfrom
h1whelan:add-output-json-to-cli-ls-commands
Open

Add --output json to flow ls, work-pool ls, task-run ls, concurrency-limit ls#20904
h1whelan wants to merge 1 commit intoPrefectHQ:mainfrom
h1whelan:add-output-json-to-cli-ls-commands

Conversation

@h1whelan
Copy link

@h1whelan h1whelan commented Mar 1, 2026

Summary

Related to #19483

Adds --output json / -o json support to four CLI list commands that were missing it:

  • flow ls
  • work-pool ls
  • task-run ls
  • concurrency-limit ls

Each follows the established pattern from flow-run ls and deployment ls:

  • Add --output / -o option (accepts "json")
  • When output == "json", serialize response objects with orjson.dumps(..., option=orjson.OPT_INDENT_2) and print
  • When not set, render the existing Rich table as before
  • Empty results return [] in JSON mode instead of a text message
  • Invalid format values produce a clear error message

Also adds proper empty-list handling (exit_with_success) for flow ls and task-run ls where it was previously missing.

Changes

File Change
src/prefect/cli/flow.py Add --output json to flow ls
src/prefect/cli/work_pool.py Add --output json to work-pool ls
src/prefect/cli/task_run.py Add --output json to task-run ls
src/prefect/cli/concurrency_limit.py Add --output json to concurrency-limit ls
tests/cli/test_flow.py Tests for flow ls JSON output
tests/cli/test_task_run.py Tests for task-run ls JSON output
tests/cli/test_work_pool.py Tests for work-pool ls JSON output
tests/cli/test_concurrency_limit.py New test file for concurrency-limit ls JSON output

Test plan

  • JSON output returns valid JSON array for each command
  • Empty results return [] (not a text message) in JSON mode
  • Invalid format (e.g. -o xml) returns error with exit code 1
  • State/name filters work with JSON output (task-run ls --state Running -o json)
  • Existing table output is unchanged when --output is not specified

…concurrency-limit ls

Related to PrefectHQ#19483

Add --output/-o json support to four CLI list commands that were
missing it, following the established pattern from flow-run ls and
deployment ls:

- flow ls
- work-pool ls
- task-run ls
- concurrency-limit ls

Each command now accepts --output json / -o json to emit
machine-readable JSON (via orjson) instead of the Rich table.
Empty results return [] in JSON mode. Invalid format values
produce a clear error.

Also adds proper empty-list handling (exit_with_success) where
it was previously missing.

Includes tests for JSON output, empty JSON output, and invalid
format rejection for all four commands.
@github-actions github-actions bot added cli Related to the Prefect CLI enhancement An improvement of an existing feature labels Mar 1, 2026
@codspeed-hq
Copy link

codspeed-hq bot commented Mar 1, 2026

Merging this PR will not alter performance

✅ 2 untouched benchmarks


Comparing h1whelan:add-output-json-to-cli-ls-commands (b5b1082) with main (13e96b7)

Open in CodSpeed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli Related to the Prefect CLI enhancement An improvement of an existing feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant