clan-cli: Refactor ssh folder part 1
This commit is contained in:
32
pkgs/clan-cli/clan_cli/ssh/results.py
Normal file
32
pkgs/clan-cli/clan_cli/ssh/results.py
Normal 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]]]
|
||||
Reference in New Issue
Block a user