Skip to content
v0.1.3

Service Command API Reference

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

bijux_cli.commands.memory.service

Implements the root callback for the bijux memory command group.

This module defines the default action for the bijux memory command. When invoked without a subcommand, it provides a summary of the transient, in-memory data store, including the number of keys currently set.

Output Contract
  • Success: {"status": "ok", "count": int|None, "message": str}
  • Verbose: Adds {"python": str, "platform": str} to the payload.
  • Error: {"error": str, "code": int}
Exit Codes
  • 0: Success.
  • 1: An unexpected error occurred (e.g., service unavailable).
  • 3: An ASCII or encoding error was detected in the environment.

memory

memory(
    ctx: Context,
    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

Defines the entrypoint for the bijux memory command group.

This function serves as the main callback. It handles --help requests and, if no subcommand is invoked, delegates to the memory_summary function to display the default summary view.

Parameters:

  • ctx (Context) –

    The Typer context for the CLI.

  • 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 runtime metadata 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:

  • Exit

    Exits after displaying help text.

Source code in src/bijux_cli/commands/memory/service.py
def memory(
    ctx: typer.Context,
    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:
    """Defines the entrypoint for the `bijux memory` command group.

    This function serves as the main callback. It handles `--help` requests and,
    if no subcommand is invoked, delegates to the `memory_summary` function to
    display the default summary view.

    Args:
        ctx (typer.Context): The Typer context for the CLI.
        quiet (bool): If True, suppresses all output except for errors.
        verbose (bool): If True, includes runtime metadata 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:
        typer.Exit: Exits after displaying help text.
    """
    if any(arg in ("-h", "--help") for arg in sys.argv):
        if ctx.invoked_subcommand:
            cmd = getattr(ctx.command, "get_command", None)
            sub_cmd = cmd(ctx, ctx.invoked_subcommand) if callable(cmd) else None
            if sub_cmd and hasattr(sub_cmd, "get_help"):
                typer.echo(
                    sub_cmd.get_help(ctx)  # pyright: ignore[reportAttributeAccessIssue]
                )
            else:
                typer.echo(ctx.get_help())
        else:
            typer.echo(ctx.get_help())
        raise typer.Exit()
    if ctx.invoked_subcommand is None:
        memory_summary(ctx, quiet, verbose, fmt, pretty, debug)

memory_summary

memory_summary(
    ctx: Context,
    quiet: bool,
    verbose: bool,
    fmt: str,
    pretty: bool,
    debug: bool,
) -> None

Handles the logic for the default bijux memory command action.

This function is called by the main Typer callback when no subcommand is specified. It resolves the memory service, gets the key count, and then executes the one-shot summary.

Parameters:

  • ctx (Context) –

    The Typer context for the CLI.

  • 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 ( None ) –

Raises:

  • SystemExit

    Always exits with a contract-compliant status code and payload upon completion or error.

Source code in src/bijux_cli/commands/memory/service.py
def memory_summary(
    ctx: typer.Context,
    quiet: bool,
    verbose: bool,
    fmt: str,
    pretty: bool,
    debug: bool,
) -> None:
    """Handles the logic for the default `bijux memory` command action.

    This function is called by the main Typer callback when no subcommand is
    specified. It resolves the memory service, gets the key count, and then
    executes the one-shot summary.

    Args:
        ctx (typer.Context): The Typer context for the CLI.
        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 upon completion or error.
    """
    command = "memory"
    include_runtime = verbose or debug

    fmt_lower = validate_common_flags(fmt, command, quiet)

    output_format = OutputFormat.YAML if fmt_lower == "yaml" else OutputFormat.JSON
    effective_pretty = debug or pretty

    svc = resolve_memory_service(command, fmt_lower, quiet, include_runtime, debug)

    keys_count = None
    with contextlib.suppress(Exception):
        keys_count = len(svc.keys())

    _run_one_shot_mode(
        command=command,
        fmt=fmt_lower,
        output_format=output_format,
        quiet=quiet,
        verbose=verbose,
        debug=debug,
        effective_pretty=effective_pretty,
        include_runtime=include_runtime,
        keys_count=keys_count,
    )