From c8f8c3392221e7b786a4855861d228b7e5cf24f6 Mon Sep 17 00:00:00 2001 From: jvican Date: Thu, 29 Aug 2019 15:32:06 +0200 Subject: [PATCH] Add `interactiveSession` flag --- cli/src/main/scala/snailgun/Cli.scala | 2 +- core/src/main/scala/snailgun/Client.scala | 8 +++++--- core/src/main/scala/snailgun/TcpClient.scala | 5 +++-- core/src/main/scala/snailgun/protocol/Protocol.scala | 5 +++-- core/src/test/scala/snailgun/SnailgunBaseSuite.scala | 5 +++-- 5 files changed, 15 insertions(+), 10 deletions(-) diff --git a/cli/src/main/scala/snailgun/Cli.scala b/cli/src/main/scala/snailgun/Cli.scala index 108e903..eb4b416 100644 --- a/cli/src/main/scala/snailgun/Cli.scala +++ b/cli/src/main/scala/snailgun/Cli.scala @@ -90,7 +90,7 @@ abstract class Cli(in: InputStream, out: PrintStream, err: PrintStream) { val logger = new SnailgunLogger("log", out, isVerbose = params.verbose) try { val code = - client.run(cmd, cmdArgs, Defaults.cwd, Defaults.env, streams, logger, noCancel) + client.run(cmd, cmdArgs, Defaults.cwd, Defaults.env, streams, logger, noCancel, true) logger.debug(s"Return code is $code") exit(code) } catch { diff --git a/core/src/main/scala/snailgun/Client.scala b/core/src/main/scala/snailgun/Client.scala index 7a85539..dd488cf 100644 --- a/core/src/main/scala/snailgun/Client.scala +++ b/core/src/main/scala/snailgun/Client.scala @@ -15,7 +15,8 @@ abstract class Client { env: Map[String, String], streams: Streams, logger: Logger, - stop: AtomicBoolean + stop: AtomicBoolean, + interactiveSession: Boolean ): Int def run( @@ -23,6 +24,7 @@ abstract class Client { args: Array[String], streams: Streams, logger: Logger, - stop: AtomicBoolean - ): Int = run(cmd, args, Defaults.cwd, Defaults.env, streams, logger, stop) + stop: AtomicBoolean, + interactiveSession: Boolean + ): Int = run(cmd, args, Defaults.cwd, Defaults.env, streams, logger, stop, interactiveSession) } diff --git a/core/src/main/scala/snailgun/TcpClient.scala b/core/src/main/scala/snailgun/TcpClient.scala index 20c0098..ae100d7 100644 --- a/core/src/main/scala/snailgun/TcpClient.scala +++ b/core/src/main/scala/snailgun/TcpClient.scala @@ -23,13 +23,14 @@ class TcpClient(addr: InetAddress, port: Int) extends Client { env: Map[String, String], streams: Streams, logger: Logger, - stop: AtomicBoolean + stop: AtomicBoolean, + interactiveSession: Boolean ): Int = { val socket = new Socket(addr, port) try { val in = socket.getInputStream() val out = socket.getOutputStream() - val protocol = new Protocol(streams, cwd, env, logger, stop) + val protocol = new Protocol(streams, cwd, env, logger, stop, interactiveSession) protocol.sendCommand(cmd, args, out, in) } finally { try { diff --git a/core/src/main/scala/snailgun/protocol/Protocol.scala b/core/src/main/scala/snailgun/protocol/Protocol.scala index e79aae0..bfc083f 100644 --- a/core/src/main/scala/snailgun/protocol/Protocol.scala +++ b/core/src/main/scala/snailgun/protocol/Protocol.scala @@ -45,7 +45,8 @@ class Protocol( cwd: Path, environment: Map[String, String], logger: Logger, - stopFurtherProcessing: AtomicBoolean + stopFurtherProcessing: AtomicBoolean, + interactiveSession: Boolean ) { private val absoluteCwd = cwd.toAbsolutePath().toString private val exitCode: AtomicInteger = new AtomicInteger(-1) @@ -60,7 +61,7 @@ class Protocol( def interactive(fd: Int): String = Integer.toString(Terminal.hasTerminalAttached(fd)) def skipIfNative(f: => String) = - if (System.getProperty("java.vm.name") == "Substrate VM") "0" else f + if (!interactiveSession || System.getProperty("java.vm.name") == "Substrate VM") "0" else f environment ++ Map( "NAILGUN_FILESEPARATOR" -> NailgunFileSeparator, "NAILGUN_PATHSEPARATOR" -> NailgunPathSeparator, diff --git a/core/src/test/scala/snailgun/SnailgunBaseSuite.scala b/core/src/test/scala/snailgun/SnailgunBaseSuite.scala index 4763527..897ea63 100644 --- a/core/src/test/scala/snailgun/SnailgunBaseSuite.scala +++ b/core/src/test/scala/snailgun/SnailgunBaseSuite.scala @@ -116,7 +116,8 @@ class SnailgunBaseSuite extends BaseSuite { Defaults.env, streams, logger, - new AtomicBoolean(false) + new AtomicBoolean(false), + true ) // Exit on Windows can sometimes return non-successful code even if exit succeeded @@ -231,7 +232,7 @@ class SnailgunBaseSuite extends BaseSuite { private val out: ByteArrayOutputStream ) { def run(cmd: String, args: Array[String]): Int = - client.run(cmd, args, Defaults.cwd, Defaults.env, streams, logger, stop) + client.run(cmd, args, Defaults.cwd, Defaults.env, streams, logger, stop, true) lazy val output: String = { new String(out.toByteArray(), StandardCharsets.UTF_8)