Skip to content
v0.1.3

Get Command API Reference

This section documents the internals of the get command in Bijux CLI.

bijux_cli.commands.config.get

Implements the config get subcommand for the Bijux CLI.

This module contains the logic for retrieving the value of a specific key from the active configuration store. It provides a structured, machine-readable response containing the value or an error if the key is not found.

Output Contract
  • Success: {"value": str}
  • Verbose: Adds {"python": str, "platform": str} to the payload.
  • Error: {"error": str, "code": int}
Exit Codes
  • 0: Success.
  • 1: An unexpected error occurred while accessing the configuration.
  • 2: The specified key was not found in the configuration.

get_config

get_config(
    ctx: Context,
    key: str = Argument(
        ..., help="Configuration key to look up"
    ),
    quiet: bool = Option(
        False, "-q", "--quiet", help=HELP_QUIET
    ),
    verbose: bool = Option(
        False, "-v", "--verbose", help=HELP_VERBOSE
    ),
    fmt: str = Option(
        "json", "-f", "--format", help=HELP_FORMAT
    ),
    pretty: bool = Option(
        True, "--pretty/--no-pretty", help=HELP_NO_PRETTY
    ),
    debug: bool = Option(
        False, "-d", "--debug", help=HELP_DEBUG
    ),
) -> None

Retrieves the value for a given configuration key.

This function fetches the value for the specified key from the configuration service and uses the new_run_command helper to emit it in a structured payload. It handles errors, such as the key not being found.

Parameters:

  • ctx (Context) –

    The Typer context for the CLI.

  • key (str, default: Argument(..., help='Configuration key to look up') ) –

    The configuration key whose value should be retrieved.

  • quiet (bool, default: Option(False, '-q', '--quiet', help=HELP_QUIET) ) –

    If True, suppresses all output except for errors.

  • verbose (bool, default: Option(False, '-v', '--verbose', help=HELP_VERBOSE) ) –

    If True, includes Python/platform details in the output.

  • fmt (str, default: Option('json', '-f', '--format', help=HELP_FORMAT) ) –

    The output format, "json" or "yaml".

  • pretty (bool, default: Option(True, '--pretty/--no-pretty', help=HELP_NO_PRETTY) ) –

    If True, pretty-prints the output.

  • debug (bool, default: Option(False, '-d', '--debug', help=HELP_DEBUG) ) –

    If True, enables debug diagnostics.

Returns:

  • None ( None ) –

Raises:

  • SystemExit

    Always exits with a contract-compliant status code and payload, indicating success or detailing the error.

Source code in src/bijux_cli/commands/config/get.py
def get_config(
    ctx: typer.Context,
    key: str = typer.Argument(..., help="Configuration key to look up"),
    quiet: bool = typer.Option(False, "-q", "--quiet", help=HELP_QUIET),
    verbose: bool = typer.Option(False, "-v", "--verbose", help=HELP_VERBOSE),
    fmt: str = typer.Option("json", "-f", "--format", help=HELP_FORMAT),
    pretty: bool = typer.Option(True, "--pretty/--no-pretty", help=HELP_NO_PRETTY),
    debug: bool = typer.Option(False, "-d", "--debug", help=HELP_DEBUG),
) -> None:
    """Retrieves the value for a given configuration key.

    This function fetches the value for the specified key from the configuration
    service and uses the `new_run_command` helper to emit it in a structured
    payload. It handles errors, such as the key not being found.

    Args:
        ctx (typer.Context): The Typer context for the CLI.
        key (str): The configuration key whose value should be retrieved.
        quiet (bool): If True, suppresses all output except for errors.
        verbose (bool): If True, includes Python/platform details in the output.
        fmt (str): The output format, "json" or "yaml".
        pretty (bool): If True, pretty-prints the output.
        debug (bool): If True, enables debug diagnostics.

    Returns:
        None:

    Raises:
        SystemExit: Always exits with a contract-compliant status code and
            payload, indicating success or detailing the error.
    """
    flags = parse_global_flags()

    quiet = flags["quiet"]
    verbose = flags["verbose"]
    fmt = flags["format"]
    pretty = flags["pretty"]
    debug = flags["debug"]

    include_runtime = verbose
    fmt_lower = fmt.lower()

    command = "config get"

    config_svc = DIContainer.current().resolve(ConfigProtocol)

    try:
        value = config_svc.get(key)
    except CommandError as exc:
        if str(exc).startswith("Config key not found"):
            emit_error_and_exit(
                f"Config key not found: {key}",
                code=2,
                failure="not_found",
                command=command,
                fmt=fmt_lower,
                quiet=quiet,
                include_runtime=include_runtime,
                debug=debug,
                extra={"key": key},
            )
        emit_error_and_exit(
            f"Failed to get config: {exc}",
            code=1,
            failure="get_failed",
            command=command,
            fmt=fmt_lower,
            quiet=quiet,
            include_runtime=include_runtime,
            debug=debug,
        )

    def payload_builder(include_runtime: bool) -> dict[str, object]:
        """Builds a payload containing the retrieved configuration value.

        Args:
            include_runtime (bool): If True, includes Python and platform info.

        Returns:
            dict[str, object]: A dictionary containing the key's value and
                optional runtime metadata.
        """
        payload: dict[str, object] = {"value": value}
        if include_runtime:
            payload["python"] = ascii_safe(platform.python_version(), "python_version")
            payload["platform"] = ascii_safe(platform.platform(), "platform")
        return payload

    new_run_command(
        command_name=command,
        payload_builder=payload_builder,
        quiet=quiet,
        verbose=verbose,
        fmt=fmt_lower,
        pretty=pretty,
        debug=debug,
    )