CLI utilities for MADSci.
This module provides common utilities for CLI commands, including output formatting, service health checking, shared formatting, and reusable Click decorators.
Sub-modules¶
madsci.client.cli.utils.cli_decorators
madsci.client.cli.utils.formatting
madsci.client.cli.utils.output
madsci.client.cli.utils.service_health
Functions¶
determine_output_format(ctx: click.Context) ‑> madsci.client.cli.utils.output.OutputFormatDetermine the output format from Click context flags.
Precedence:
--json>--yaml>-q/--quiet> table (default).Args: ctx: Click context populated by the top-level
madscigroup.Returns: The :class:
OutputFormatto use.error(console: Console, message: str, details: str | None = None) ‑> NonePrint error message with red X.
Args: console: Rich console instance. message: Error message. details: Optional additional details.
get_console(ctx: click.Context) ‑> rich.console.ConsoleGet Rich Console from Click context, with fallback.
All CLI commands should use this function instead of creating their own Console or inlining
ctx.obj.get(...).Args: ctx: Click context.
Returns: Console instance from context, or a new default Console.
info(console: Console, message: str) ‑> NonePrint info message with blue info icon.
Args: console: Rich console instance. message: Info message.
output_result(console: Console, data: Any, format: str = 'text', title: str | None = None, columns: Sequence[ColumnDef] | None = None, quiet_key: str | None = None) ‑> NoneOutput data in the requested format.
Enhanced to support:
Pydantic model auto-serialisation
:class:
ColumnDef-based table renderingquietmode (prints only the quiet_key value)Lists of Pydantic models
Args: console: Rich console instance. data: Data to output (dict, list, Pydantic model, or scalar). format: Output format (
"text","json","yaml","quiet"). title: Optional title for formatted output. columns: Optional column definitions for table rendering. quiet_key: Key whose value is printed inquietmode.success(console: Console, message: str) ‑> NonePrint success message with green checkmark.
Args: console: Rich console instance. message: Message to print.
warning(console: Console, message: str, details: str | None = None) ‑> NonePrint warning message with yellow warning sign.
Args: console: Rich console instance. message: Warning message. details: Optional additional details.
Classes¶
ColumnDef(header: ForwardRef('str'), key: ForwardRef('str'), style: ForwardRef('str | None') = None, max_width: ForwardRef('int | None') = None)Definition of a single table column.
Attributes: header: Column header text. key: Attribute / dictionary key to extract the value from each row. style: Optional Rich style for the column (e.g.
"cyan"). max_width: Optional maximum character width.Ancestors (in MRO)¶
builtins.tuple
Instance variables¶
header: str- Alias for field number 0
key: str- Alias for field number 1
max_width: int | None- Alias for field number 3
style: str | None- Alias for field number 2
OutputFormat(*args, **kwds)Supported CLI output formats.
Ancestors (in MRO)¶
builtins.str
enum.Enum
Class variables¶
JSON:QUIET:TABLE:YAML: