From 5ceec3844accbd630251011483564a1166b11da3 Mon Sep 17 00:00:00 2001 From: Qubasa Date: Wed, 29 Jan 2025 19:18:02 +0700 Subject: [PATCH] clan-cli: Add from_host function to Host class --- pkgs/clan-cli/clan_cli/ssh/host.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/pkgs/clan-cli/clan_cli/ssh/host.py b/pkgs/clan-cli/clan_cli/ssh/host.py index 3ea9f8711..778fd843e 100644 --- a/pkgs/clan-cli/clan_cli/ssh/host.py +++ b/pkgs/clan-cli/clan_cli/ssh/host.py @@ -39,10 +39,28 @@ class Host: if not self.command_prefix: self.command_prefix = self.host + def __str__(self) -> str: + return self.target + @property def target(self) -> str: return f"{self.user or 'root'}@{self.host}" + @classmethod + def from_host(cls, host: "Host") -> "Host": + return cls( + host=host.host, + user=host.user, + port=host.port, + key=host.key, + forward_agent=host.forward_agent, + command_prefix=host.command_prefix, + host_key_check=host.host_key_check, + meta=host.meta.copy(), + verbose_ssh=host.verbose_ssh, + ssh_options=host.ssh_options.copy(), + ) + def run_local( self, cmd: list[str],