Skip to content
v0.1.3

Set Command API Reference

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

bijux_cli.commands.memory.set

Implements the memory set subcommand for the Bijux CLI.

This module contains the logic for storing a key-value pair in a transient, in-memory data store. The data persists only for the lifetime of the application's parent process. A structured confirmation is emitted upon success.

Output Contract
  • Success: {"status": "updated", "key": str, "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 (e.g., service unavailable, set failed).
  • 2: The provided key was invalid.

set_memory

set_memory(
    key: str = Argument(..., help="Key to set"),
    value: str = Argument(..., help="Value to set"),
    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

Sets a key-value pair in the transient in-memory store.

This command validates the key's format and then stores the key-value pair using the memory service.

Parameters:

  • key (str, default: Argument(..., help='Key to set') ) –

    The memory key to set. Must be between 1 and 4096 printable, non-whitespace characters.

  • value (str, default: Argument(..., help='Value to set') ) –

    The value to associate with the key.

  • 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 an error.

Source code in src/bijux_cli/commands/memory/set.py
def set_memory(
    key: str = typer.Argument(..., help="Key to set"),
    value: str = typer.Argument(..., help="Value to set"),
    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:
    """Sets a key-value pair in the transient in-memory store.

    This command validates the key's format and then stores the key-value
    pair using the memory service.

    Args:
        key (str): The memory key to set. Must be between 1 and 4096 printable,
            non-whitespace characters.
        value (str): The value to associate with the key.
        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 an error.
    """
    command = "memory set"

    fmt_lower = validate_common_flags(fmt, command, quiet)

    if not (
        1 <= len(key) <= 4096 and all(c.isprintable() and not c.isspace() for c in key)
    ):
        emit_error_and_exit(
            "Invalid key: must be 1-4096 printable non-space characters",
            code=2,
            failure="invalid_key",
            command=command,
            fmt=fmt_lower,
            quiet=quiet,
            include_runtime=verbose,
            debug=debug,
        )

    memory_svc = resolve_memory_service(command, fmt_lower, quiet, verbose, debug)

    try:
        memory_svc.set(key, value)
    except Exception as exc:
        emit_error_and_exit(
            f"Failed to set memory: {exc}",
            code=1,
            failure="set_failed",
            command=command,
            fmt=fmt_lower,
            quiet=quiet,
            include_runtime=verbose,
            debug=debug,
        )

    new_run_command(
        command_name=command,
        payload_builder=lambda include: _build_payload(include, key, value),
        quiet=quiet,
        verbose=verbose,
        fmt=fmt_lower,
        pretty=pretty,
        debug=debug,
    )