Imported from gencau/test-practices-agent-configurations (
dataset/repos/prefecthq§prefect/src/prefect/cli/AGENTS.md). Install upstream withnpx skills add gencau/test-practices-agent-configurations --skill cli. Copyright stays with the author.
CLI
Prefect command-line interface, powered by cyclopts.
Key Contracts
- Use
richfor all output. Console output viarich.console, tables viarich.table, progress bars viarich.progress. Always useexit_with_errorfor error exits. - Support JSON output whenever possible. Commands should have a
--jsonflag or equivalent for machine-readable output. - Excluded from
prefect-client— the entirecli/directory is stripped during the client package build.
Structure
_app.py— Rootcyclopts.Appand session-level flags (--profile,--prompt)- Top-level files — One file per command group:
flow.py,task.py,server.py,worker.py,block.py,deployment.py,variable.py,work_pool.py, etc. deploy/—prefect deploysubcommand — the most complex subcommand with its own internal module structurecloud/—prefect cloudsubcommands (login, workspace, webhooks, IP allowlists)transfer/—prefect transfersubcommands_utilities.py,_prompts.py,_server_utils.py,_cloud_utils.py,_worker_utils.py— Internal helpers (prefixed with_)flow_runs_watching.py— Command-specific support module forflow-run watch; provideswatch_flow_run()andFlowRunFormatter. Not prefixed with_— command-specific helpers may omit the prefix.
Testing
uv run pytest tests/cli/ -x -n4 # All CLI tests
uv run pytest tests/cli/test_flow.py # Single command group
uv run pytest tests/cli/deploy/ # Deploy subcommand tests
Related
tests/cli/→ CLI tests mirror this directory structure