render_output(data, fmt, *, text_render=None)
Render data in the requested format.
When fmt is OutputFormat.json the data is serialised to JSON. When fmt is OutputFormat.text text_render is called if provided; otherwise the data is printed via the Rich console.
Source code in src/cli_app/utils/output.py
| def render_output(
data: dict[str, Any] | list[Any],
fmt: OutputFormat,
*,
text_render: Callable[[], None] | None = None,
) -> None:
"""Render *data* in the requested format.
When *fmt* is ``OutputFormat.json`` the data is serialised to JSON.
When *fmt* is ``OutputFormat.text`` *text_render* is called if provided;
otherwise the data is printed via the Rich console.
"""
if fmt == OutputFormat.json:
echo_json(data)
elif text_render is not None:
text_render()
else:
get_console().print(data)
|