Merge pull request 'cli/ssh: allocate tty by default' (#1043) from Mic92-main into main
This commit is contained in:
6
flake.lock
generated
6
flake.lock
generated
@@ -63,11 +63,11 @@
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1711327729,
|
||||
"narHash": "sha256-RzOXI1kBlK7HkeZfRjUnsBUJEmlMYgLEG7CziZN0lgs=",
|
||||
"lastModified": 1711375484,
|
||||
"narHash": "sha256-+d4HqehyQvuHUKR8Nv9HGGd/SP5wjg3MA/hEYJBWQq0=",
|
||||
"owner": "nix-community",
|
||||
"repo": "nixos-generators",
|
||||
"rev": "d3e8145766dad6b47f6e37ce28731a05144dec26",
|
||||
"rev": "2b3720c7af2271be8cee713cd2f69c5127b0a8e4",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
options = [
|
||||
"-eucx"
|
||||
''
|
||||
${lib.getExe pkgs.ruff} --fix "$@"
|
||||
${lib.getExe pkgs.ruff} check --fix "$@"
|
||||
${lib.getExe pkgs.ruff} format "$@"
|
||||
''
|
||||
"--" # this argument is ignored by bash
|
||||
|
||||
@@ -398,8 +398,9 @@ class Host:
|
||||
extra_env: dict[str, str] = {},
|
||||
cwd: None | str | Path = None,
|
||||
check: bool = True,
|
||||
verbose_ssh: bool = False,
|
||||
timeout: float = math.inf,
|
||||
verbose_ssh: bool = False,
|
||||
tty: bool = False,
|
||||
) -> subprocess.CompletedProcess[str]:
|
||||
"""
|
||||
Command to run on the host via ssh
|
||||
@@ -444,7 +445,7 @@ class Host:
|
||||
bash_cmd += cmd
|
||||
# FIXME we assume bash to be present here? Should be documented...
|
||||
ssh_cmd = [
|
||||
*self.ssh_cmd(verbose_ssh=verbose_ssh),
|
||||
*self.ssh_cmd(verbose_ssh=verbose_ssh, tty=tty),
|
||||
"--",
|
||||
f"{sudo}bash -c {quote(bash_cmd)} -- {' '.join(map(quote, bash_args))}",
|
||||
]
|
||||
@@ -462,6 +463,7 @@ class Host:
|
||||
def ssh_cmd(
|
||||
self,
|
||||
verbose_ssh: bool = False,
|
||||
tty: bool = False,
|
||||
) -> list[str]:
|
||||
if self.user is not None:
|
||||
ssh_target = f"{self.user}@{self.host}"
|
||||
@@ -484,6 +486,8 @@ class Host:
|
||||
ssh_opts.extend(["-o", "UserKnownHostsFile=/dev/null"])
|
||||
if verbose_ssh or self.verbose_ssh:
|
||||
ssh_opts.extend(["-v"])
|
||||
if tty:
|
||||
ssh_opts.extend(["-t"])
|
||||
|
||||
return ["ssh", ssh_target, *ssh_opts]
|
||||
|
||||
@@ -547,6 +551,7 @@ class HostGroup:
|
||||
check: bool = True,
|
||||
verbose_ssh: bool = False,
|
||||
timeout: float = math.inf,
|
||||
tty: bool = False,
|
||||
) -> None:
|
||||
try:
|
||||
proc = host.run_local(
|
||||
@@ -575,6 +580,7 @@ class HostGroup:
|
||||
check: bool = True,
|
||||
verbose_ssh: bool = False,
|
||||
timeout: float = math.inf,
|
||||
tty: bool = False,
|
||||
) -> None:
|
||||
try:
|
||||
proc = host.run(
|
||||
@@ -586,6 +592,7 @@ class HostGroup:
|
||||
check=check,
|
||||
verbose_ssh=verbose_ssh,
|
||||
timeout=timeout,
|
||||
tty=tty,
|
||||
)
|
||||
results.append(HostResult(host, proc))
|
||||
except Exception as e:
|
||||
@@ -616,8 +623,9 @@ class HostGroup:
|
||||
extra_env: dict[str, str] = {},
|
||||
cwd: None | str | Path = None,
|
||||
check: bool = True,
|
||||
verbose_ssh: bool = False,
|
||||
timeout: float = math.inf,
|
||||
verbose_ssh: bool = False,
|
||||
tty: bool = False,
|
||||
) -> Results:
|
||||
results: Results = []
|
||||
threads = []
|
||||
@@ -634,8 +642,9 @@ class HostGroup:
|
||||
extra_env=extra_env,
|
||||
cwd=cwd,
|
||||
check=check,
|
||||
verbose_ssh=verbose_ssh,
|
||||
timeout=timeout,
|
||||
verbose_ssh=verbose_ssh,
|
||||
tty=tty,
|
||||
),
|
||||
)
|
||||
thread.start()
|
||||
@@ -659,6 +668,7 @@ class HostGroup:
|
||||
check: bool = True,
|
||||
verbose_ssh: bool = False,
|
||||
timeout: float = math.inf,
|
||||
tty: bool = False,
|
||||
) -> Results:
|
||||
"""
|
||||
Command to run on the remote host via ssh
|
||||
@@ -679,6 +689,7 @@ class HostGroup:
|
||||
check=check,
|
||||
verbose_ssh=verbose_ssh,
|
||||
timeout=timeout,
|
||||
tty=tty,
|
||||
)
|
||||
|
||||
def run_local(
|
||||
|
||||
Reference in New Issue
Block a user