Host: convert to proctocol to avoid forced inheritance

This commit is contained in:
Johannes Kirschbauer
2025-08-08 22:33:05 +02:00
parent 110d1d4921
commit 58fa7ac32b
3 changed files with 8 additions and 10 deletions

View File

@@ -1,24 +1,24 @@
"""Base Host interface for both local and remote command execution."""
import logging
from abc import ABC, abstractmethod
from abc import abstractmethod
from collections.abc import Iterator
from contextlib import contextmanager
from dataclasses import dataclass
from typing import Protocol
from clan_lib.cmd import CmdOut, RunOpts
cmdlog = logging.getLogger(__name__)
@dataclass(frozen=True)
class Host(ABC):
class Host(Protocol):
"""
Abstract base class for host command execution.
This provides a common interface for both local and remote hosts.
"""
command_prefix: str | None
@property
def command_prefix(self) -> str | None: ...
@property
@abstractmethod

View File

@@ -6,13 +6,12 @@ from dataclasses import dataclass, field
from clan_lib.cmd import CmdOut, RunOpts, run
from clan_lib.colors import AnsiColor
from clan_lib.ssh.host import Host
cmdlog = logging.getLogger(__name__)
@dataclass(frozen=True)
class LocalHost(Host):
class LocalHost:
"""
A Host implementation that executes commands locally without SSH.
"""
@@ -42,7 +41,7 @@ class LocalHost(Host):
control_master: bool = True,
) -> CmdOut:
"""
Run a command locally instead of via SSH.
Run a command locally.
"""
if opts is None:
opts = RunOpts()

View File

@@ -16,7 +16,6 @@ from clan_lib.cmd import CmdOut, RunOpts, run
from clan_lib.colors import AnsiColor
from clan_lib.errors import ClanError, indent_command # Assuming these are available
from clan_lib.nix import nix_shell
from clan_lib.ssh.host import Host
from clan_lib.ssh.host_key import HostKeyCheck, hostkey_to_ssh_opts
from clan_lib.ssh.parse import parse_ssh_uri
from clan_lib.ssh.sudo_askpass_proxy import SudoAskpassProxy
@@ -31,7 +30,7 @@ NO_OUTPUT_TIMEOUT = 20
@dataclass(frozen=True)
class Remote(Host):
class Remote:
address: str
command_prefix: str | None
user: str = "root"