Context Object for the CLI.
Attributes
| Attribute | Type | Description |
|---|
| app | Application | The application instance associated with this context, defaulting to the current active application if not provided. |
| no_color | boolean | A boolean flag that, when true, disables ANSI color codes in terminal output. |
| quiet | boolean = False | A boolean flag used to suppress non-essential output and incoming message notifications. |
| workdir | string | The file system path representing the current working directory for CLI operations. |
| OK | string | A cached, styled string representing a successful status label, typically rendered in bold green. |
| ERROR | string | A cached, styled string representing an error status label, typically rendered in bold red. |
Constructor
Signature
def CLIContext(
app: Any,
no_color: bool,
workdir: str,
quiet: bool = False
) - > null
Parameters
| Name | Type | Description |
|---|
| app | Any | The application instance or context |
| no_color | bool | Flag to disable colored output |
| workdir | str | The working directory for the CLI |
| quiet | bool = False | Flag to suppress non-essential output |
Signature
def CLIContext(
app: object,
no_color: boolean,
workdir: string,
quiet: boolean = False
)
Parameters
| Name | Type | Description |
|---|
| app | object | The application instance to associate with this context; defaults to the current active app if not provided |
| no_color | boolean | A flag to disable ANSI color codes in terminal output |
| workdir | string | The filesystem path representing the current working directory for CLI operations |
| quiet | boolean = False | A flag to suppress non-essential output messages |
Methods
OK()
@classmethod
def OK() - > string
Returns a styled "OK" string, typically bold and green, for indicating successful operations.
Returns
| Type | Description |
|---|
string | The styled success indicator string |
ERROR()
@classmethod
def ERROR() - > string
Returns a styled "ERROR" string, typically bold and red, for indicating failed operations.
Returns
| Type | Description |
|---|
string | The styled error indicator string |
style()
@classmethod
def style(
message: string,
kwargs: dict
) - > string
Applies ANSI color and style attributes to a message unless color output is disabled in the context.
Parameters
| Name | Type | Description |
|---|
| message | string | The text content to be styled |
| kwargs | dict | Styling options such as 'fg' (foreground color), 'bg' (background color), or 'bold' |
Returns
| Type | Description |
|---|
string | The message string wrapped in ANSI escape codes, or the original message if no_color is active |
secho()
@classmethod
def secho(
message: string,
kwargs: dict
)
Prints a styled message to the terminal, automatically handling the context's color preferences.
Parameters
| Name | Type | Description |
|---|
| message | string | The text content to print |
| kwargs | dict | Styling and output arguments passed to the underlying click.secho implementation |
echo()
@classmethod
def echo(
message: string,
kwargs: dict
)
Prints a message to the terminal, ensuring color is disabled if the context's no_color flag is set.
Parameters
| Name | Type | Description |
|---|
| message | string | The text content to print |
| kwargs | dict | Standard output arguments passed to the underlying click.echo implementation |
error()
@classmethod
def error(
message: string,
kwargs: dict
)
Prints a message to the standard error stream (stderr) with appropriate styling or color suppression.
Parameters
| Name | Type | Description |
|---|
| message | string | The error message text to display |
| kwargs | dict | Additional formatting arguments; 'err=True' is automatically included |
pretty()
@classmethod
def pretty(
n: any
) - > tuple
Formats various data types into human-readable, potentially syntax-highlighted strings for CLI display.
Parameters
| Name | Type | Description |
|---|
| n | any | The data object (list, dict, string, etc.) to be formatted for display |
Returns
| Type | Description |
|---|
tuple | A tuple containing a status indicator (OK/ERROR) and the formatted string representation of the input |
pretty_list()
@classmethod
def pretty_list(
n: list
) - > string
Converts a list into a bulleted string representation suitable for terminal output.
Parameters
| Name | Type | Description |
|---|
| n | list | The list of items to format |
Returns
| Type | Description |
|---|
string | A newline-separated string of bulleted items, or '- empty -' if the list is null or empty |
pretty_dict_ok_error()
@classmethod
def pretty_dict_ok_error(
n: dict
) - > tuple
Parses a dictionary containing 'ok' or 'error' keys to return a status-prefixed, indented result.
Parameters
| Name | Type | Description |
|---|
| n | dict | A dictionary expected to contain either an 'ok' or 'error' key for status-based formatting |
Returns
| Type | Description |
|---|
tuple | A tuple of (OK, formatted_value) if 'ok' exists, otherwise (ERROR, formatted_value) for the 'error' key |
say_chat()
@classmethod
def say_chat(
direction: string,
title: string,
body: string = '',
show_body: boolean = False
)
Displays a formatted chat-like message with a direction indicator, title, and optional body text.
Parameters
| Name | Type | Description |
|---|
| direction | string | A string indicating message flow (e.g., '< -' or '- >') used as a prefix |
| title | string | The primary header or subject of the chat message |
| body | string = '' | The detailed content of the message to be displayed if show_body is true |
| show_body | boolean = False | Controls whether the body text is printed below the title |