Skip to main content

CLIContext

Context Object for the CLI.

Attributes​

AttributeTypeDescription
appApplicationThe application instance associated with this context, defaulting to the current active application if not provided.
no_colorbooleanA boolean flag that, when true, disables ANSI color codes in terminal output.
quietboolean = FalseA boolean flag used to suppress non-essential output and incoming message notifications.
workdirstringThe file system path representing the current working directory for CLI operations.
OKstringA cached, styled string representing a successful status label, typically rendered in bold green.
ERRORstringA 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​

NameTypeDescription
appAnyThe application instance or context
no_colorboolFlag to disable colored output
workdirstrThe working directory for the CLI
quietbool = FalseFlag to suppress non-essential output

Signature​

def CLIContext(
app: object,
no_color: boolean,
workdir: string,
quiet: boolean = False
)

Parameters​

NameTypeDescription
appobjectThe application instance to associate with this context; defaults to the current active app if not provided
no_colorbooleanA flag to disable ANSI color codes in terminal output
workdirstringThe filesystem path representing the current working directory for CLI operations
quietboolean = FalseA 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​

TypeDescription
stringThe styled success indicator string

ERROR()​

@classmethod
def ERROR() - > string

Returns a styled "ERROR" string, typically bold and red, for indicating failed operations.

Returns​

TypeDescription
stringThe 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​

NameTypeDescription
messagestringThe text content to be styled
kwargsdictStyling options such as 'fg' (foreground color), 'bg' (background color), or 'bold'

Returns​

TypeDescription
stringThe 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​

NameTypeDescription
messagestringThe text content to print
kwargsdictStyling 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​

NameTypeDescription
messagestringThe text content to print
kwargsdictStandard 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​

NameTypeDescription
messagestringThe error message text to display
kwargsdictAdditional 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​

NameTypeDescription
nanyThe data object (list, dict, string, etc.) to be formatted for display

Returns​

TypeDescription
tupleA 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​

NameTypeDescription
nlistThe list of items to format

Returns​

TypeDescription
stringA 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​

NameTypeDescription
ndictA dictionary expected to contain either an 'ok' or 'error' key for status-based formatting

Returns​

TypeDescription
tupleA 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​

NameTypeDescription
directionstringA string indicating message flow (e.g., '< -' or '- >') used as a prefix
titlestringThe primary header or subject of the chat message
bodystring = ''The detailed content of the message to be displayed if show_body is true
show_bodyboolean = FalseControls whether the body text is printed below the title