Coverage for / home / runner / work / bijux-cli / bijux-cli / src / bijux_cli / cli / commands / memory / resolve.py: 100%
10 statements
« prev ^ index » next coverage.py v7.13.2, created at 2026-01-26 17:59 +0000
« prev ^ index » next coverage.py v7.13.2, created at 2026-01-26 17:59 +0000
1# SPDX-License-Identifier: Apache-2.0
2# Copyright © 2025 Bijan Mousavi
4"""Provides shared utilities for the `bijux memory` command group.
6This module centralizes common logic used by the memory-related subcommands.
7Its primary responsibility is to provide a consistent way to resolve the
8`MemoryProtocol` service from the Dependency Injection (DI) container,
9including standardized error handling for cases where the service is
10unavailable.
11"""
13from __future__ import annotations
15from bijux_cli.cli.core.command import raise_exit_intent
16from bijux_cli.core.di import DIContainer
17from bijux_cli.core.enums import ErrorType, LogLevel, OutputFormat
18from bijux_cli.services.diagnostics.contracts import MemoryProtocol
21def resolve_memory_service(
22 command: str,
23 fmt_lower: OutputFormat,
24 quiet: bool,
25 include_runtime: bool,
26 log_level: LogLevel,
27) -> MemoryProtocol:
28 """Resolves the MemoryProtocol implementation from the DI container.
30 Args:
31 command (str): The full command name (e.g., "memory list").
32 fmt_lower (OutputFormat): The chosen output format.
33 quiet (bool): If True, suppresses non-error output.
34 include_runtime (bool): If True, includes runtime metadata in errors.
35 log_level (LogLevel): Logging level for diagnostics.
37 Returns:
38 MemoryProtocol: An instance of the memory service.
40 Raises:
41 SystemExit: Exits with a structured error if the service cannot be
42 resolved from the container.
43 """
44 try:
45 return DIContainer.current().resolve(MemoryProtocol)
46 except Exception as exc:
47 raise_exit_intent(
48 f"Memory service unavailable: {exc}",
49 code=1,
50 failure="service_unavailable",
51 error_type=ErrorType.INTERNAL,
52 command=command,
53 fmt=fmt_lower,
54 quiet=quiet,
55 include_runtime=include_runtime,
56 log_level=log_level,
57 )