Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions lib/python/base_cli/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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."""
Expand Down
6 changes: 4 additions & 2 deletions lib/python/base_cli/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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",
Expand Down
13 changes: 3 additions & 10 deletions lib/python/base_cli/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.
Expand All @@ -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,
Expand Down Expand Up @@ -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),
)

Expand Down
6 changes: 6 additions & 0 deletions tests/test_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from pathlib import Path

import base_cli
from base_cli import history
from base_cli.testing import invoke


Expand Down Expand Up @@ -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,
Expand Down