Skip to content

ccproxy.cli.helpers

ccproxy.cli.helpers

CLI helper utilities for CCProxy API.

get_plugin_cli_args

get_plugin_cli_args(ctx=None)

Return plugin-injected CLI args from Typer context.

Ensures a dict is returned. If no context is provided, attempts to fetch the current Click/Typer context. This is safe to call from command bodies.

Source code in ccproxy/cli/helpers.py
def get_plugin_cli_args(ctx: typer.Context | None = None) -> dict[str, Any]:
    """Return plugin-injected CLI args from Typer context.

    Ensures a dict is returned. If no context is provided, attempts to fetch the
    current Click/Typer context. This is safe to call from command bodies.
    """
    try:
        if ctx is None:
            # Lazy import to avoid hard dependency when not in CLI execution
            from click import get_current_context as _get_ctx

            ctx = _get_ctx(silent=True)  # type: ignore[assignment]
        if ctx and getattr(ctx, "obj", None) and isinstance(ctx.obj, dict):
            data = ctx.obj.get("plugin_cli_args")
            if isinstance(data, dict):
                # Only return non-None values to simplify merging
                return {k: v for k, v in data.items() if v is not None}
    except Exception:
        pass
    return {}