diff --git a/lib/python/base_cli/context.py b/lib/python/base_cli/context.py index 764e696..83a3834 100644 --- a/lib/python/base_cli/context.py +++ b/lib/python/base_cli/context.py @@ -10,6 +10,7 @@ from ._cleanup import remove_owned_temp_directory from .config import FrameworkConfig +from .history import display_command as _default_history_display_command _current_context: contextvars.ContextVar[Context[Any, Any, Any] | None] = contextvars.ContextVar( "base_cli_current_context", @@ -32,10 +33,6 @@ ] -def _default_history_display_command(cli_name: str, _argv: list[str]) -> str: - return cli_name.replace("_", "-") - - @dataclass class Context(Generic[ConfigT, ApplicationStateT, ServicesT]): """Runtime state and cleanup hooks available to an active CLI command.""" diff --git a/lib/python/base_cli/history.py b/lib/python/base_cli/history.py index 9c40a8d..675b697 100644 --- a/lib/python/base_cli/history.py +++ b/lib/python/base_cli/history.py @@ -5,7 +5,7 @@ import platform from datetime import datetime, timezone from pathlib import Path -from typing import Any +from typing import TYPE_CHECKING, Any try: import fcntl as _fcntl @@ -18,9 +18,11 @@ _msvcrt = None # type: ignore[assignment] from ._private_files import restrict_file, write_private_json -from .context import Context from .redaction import REDACTED, is_secret_key, option_name_to_parameter, redact_argv, redact_text_value +if TYPE_CHECKING: + from .context import Context + __all__ = [ "HISTORY_SCOPE_INTERNAL", "HISTORY_SCOPE_PRIMARY", diff --git a/lib/python/base_cli/profile.py b/lib/python/base_cli/profile.py index 6a41665..1128640 100644 --- a/lib/python/base_cli/profile.py +++ b/lib/python/base_cli/profile.py @@ -12,6 +12,7 @@ load_yaml_file, ) from .context import Context +from .history import display_command as _generic_history_display_command from .paths import default_cache_root, default_config_root, make_run_id, normalize_cli_name from .runtime import RuntimeLayout @@ -138,10 +139,6 @@ def _no_workspace_root(_user_config: object | None) -> Path | None: return None -def _generic_history_display_command(cli_name: str, _argv: list[str]) -> str: - return cli_name.replace("_", "-") - - @dataclass(frozen=True) class CliProfile: """Policy boundary between the generic CLI lifecycle and its consumer. @@ -157,10 +154,7 @@ class CliProfile: resolve_runtime: RuntimeResolver history_writer: HistoryWriter | None = None display_command: DisplayCommandResolver = _no_display_command - history_display_command: HistoryDisplayResolver = cast( - HistoryDisplayResolver, - _generic_history_display_command, - ) + history_display_command: HistoryDisplayResolver = _generic_history_display_command resolve_workspace_root: WorkspaceRootResolver = cast( WorkspaceRootResolver, _no_workspace_root, @@ -191,8 +185,7 @@ def generic( load_config=load_config or cast(ConfigLoader, _load_explicit_config), resolve_runtime=resolve_runtime or _generic_runtime_resolver(cache_root, application_home), display_command=_no_display_command, - history_display_command=history_display_command - or cast(HistoryDisplayResolver, _generic_history_display_command), + history_display_command=history_display_command or _generic_history_display_command, resolve_workspace_root=resolve_workspace_root or cast(WorkspaceRootResolver, _no_workspace_root), ) diff --git a/tests/test_profile.py b/tests/test_profile.py index 6a7145f..fe4af56 100644 --- a/tests/test_profile.py +++ b/tests/test_profile.py @@ -6,6 +6,7 @@ from pathlib import Path import base_cli +from base_cli import history from base_cli.testing import invoke @@ -118,6 +119,11 @@ def test_generic_profile_accepts_consumer_history_display_policy(self) -> None: self.assertIs(profile.history_display_command, formatter) + def test_generic_profile_uses_shared_history_display_command(self) -> None: + profile = base_cli.CliProfile.generic() + + self.assertIs(profile.history_display_command, history.display_command) + def test_generic_profile_accepts_a_public_runtime_resolver(self) -> None: def resolve_runtime( _cli_name: str,