Utils
provide.foundation.cli.utils
¶
Common CLI utilities for output, logging, and testing.
Classes¶
CliTestRunner
¶
Test runner for CLI commands using Click's testing facilities.
Source code in provide/foundation/cli/utils.py
Functions¶
invoke
¶
invoke(
cli: Command | Group,
args: list[str] | None = None,
input: str | None = None,
env: dict[str, str] | None = None,
catch_exceptions: bool = True,
**kwargs: Any
) -> Result
Invoke a CLI command for testing.
Source code in provide/foundation/cli/utils.py
Functions¶
assert_cli_error
¶
assert_cli_error(
result: Result,
expected_error: str | None = None,
exit_code: int | None = None,
) -> None
Assert that a CLI command failed.
Source code in provide/foundation/cli/utils.py
assert_cli_success
¶
Assert that a CLI command succeeded.
Source code in provide/foundation/cli/utils.py
create_cli_context
¶
Create a CLIContext for CLI usage.
Loads from environment, then overlays any provided kwargs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
Any
|
Override values for the context |
{}
|
Returns:
| Type | Description |
|---|---|
CLIContext
|
Configured CLIContext instance |
Source code in provide/foundation/cli/utils.py
echo_error
¶
echo_info
¶
echo_json
¶
echo_success
¶
echo_warning
¶
setup_cli_logging
¶
Setup logging for CLI applications using a CLIContext object.
This function is the designated way to configure logging within a CLI application built with foundation. It uses the provided context object to construct a full TelemetryConfig and initializes the system.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ctx
|
CLIContext
|
The foundation CLIContext, populated by CLI decorators. |
required |
reinit_logging
|
bool
|
Whether to force re-initialization of logging (default: True). Set to False when embedding Foundation in a host application to avoid clobbering the host's logging configuration. |
True
|