Allow remotes to be launched in new Windows terminal windows (#504)

This commit is contained in:
Roey Darwish Dror
2020-08-23 09:12:40 +03:00
committed by GitHub
parent 201910ed28
commit 34c74e44ca
2 changed files with 33 additions and 21 deletions

View File

@@ -1,29 +1,42 @@
#[cfg(unix)]
use crate::error::SkipStep;
use crate::{execution_context::ExecutionContext, terminal::print_separator, utils};
use crate::{error::SkipStep, execution_context::ExecutionContext, terminal::print_separator, utils};
use anyhow::Result;
fn prepare_async_ssh_command(args: &mut Vec<&str>) {
args.insert(0, "ssh");
args.push("--keep");
}
pub fn ssh_step(ctx: &ExecutionContext, hostname: &str) -> Result<()> {
let ssh = utils::require("ssh")?;
let topgrade = ctx.config().remote_topgrade_path();
let mut args = vec!["-t", hostname];
if let Some(ssh_arguments) = ctx.config().ssh_arguments() {
args.extend(ssh_arguments.split_whitespace());
}
let env = format!("TOPGRADE_PREFIX={}", hostname);
args.extend(&["env", &env, topgrade]);
if ctx.config().yes() {
args.push("-y");
}
if ctx.config().run_in_tmux() && !ctx.run_type().dry() {
#[cfg(unix)]
{
let command = format!(
"{ssh} -t {hostname} env TOPGRADE_PREFIX={hostname} TOPGRADE_KEEP_END=1 {topgrade}",
ssh = ssh.display(),
hostname = hostname,
topgrade = topgrade
);
crate::tmux::run_command(ctx, &command)?;
prepare_async_ssh_command(&mut args);
crate::tmux::run_command(ctx, &args.join(" "))?;
Err(SkipStep(String::from("Remote Topgrade launched in Tmux")).into())
}
#[cfg(not(unix))]
unreachable!("Tmux execution is only implemented in Unix");
} else if ctx.config().open_remotes_in_new_terminal() && !ctx.run_type().dry() && cfg!(windows) {
prepare_async_ssh_command(&mut args);
ctx.run_type().execute("wt").args(&args).spawn()?;
Err(SkipStep(String::from("Remote Topgrade launched in an external terminal")).into())
} else {
let mut args = vec!["-t", hostname];