Skip to content

Commit

Permalink
Add interactiveSession flag
Browse files Browse the repository at this point in the history
  • Loading branch information
jvican committed Aug 29, 2019
1 parent 07214c7 commit c8f8c33
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion cli/src/main/scala/snailgun/Cli.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 5 additions & 3 deletions core/src/main/scala/snailgun/Client.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@ abstract class Client {
env: Map[String, String],
streams: Streams,
logger: Logger,
stop: AtomicBoolean
stop: AtomicBoolean,
interactiveSession: Boolean
): Int

def run(
cmd: String,
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)
}
5 changes: 3 additions & 2 deletions core/src/main/scala/snailgun/TcpClient.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 3 additions & 2 deletions core/src/main/scala/snailgun/protocol/Protocol.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions core/src/test/scala/snailgun/SnailgunBaseSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit c8f8c33

Please sign in to comment.