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