clan-cli: Refactor ssh folder part 1

This commit is contained in:
Qubasa
2024-11-21 13:02:22 +01:00
parent 8682e17012
commit 4104374b76
17 changed files with 1796 additions and 970 deletions

View File

@@ -0,0 +1,32 @@
import subprocess
from typing import Generic
from clan_cli.ssh import T
from clan_cli.ssh.host import Host
class HostResult(Generic[T]):
def __init__(self, host: Host, result: T | Exception) -> None:
self.host = host
self._result = result
@property
def error(self) -> Exception | None:
"""
Returns an error if the command failed
"""
if isinstance(self._result, Exception):
return self._result
return None
@property
def result(self) -> T:
"""
Unwrap the result
"""
if isinstance(self._result, Exception):
raise self._result
return self._result
Results = list[HostResult[subprocess.CompletedProcess[str]]]