Notify about shell less

+ Don't notify ScriptMain users by moving the logic to xMain
+ Only trigger shell if shell is a defined command
+ Use existing Shell/BootCommand strings instead of new ones
This commit is contained in:
Dale Wijnand 2017-03-21 13:08:47 +00:00
parent 8b74f1d9d3
commit bd59f14f08
No known key found for this signature in database
GPG Key ID: 4F256E3D151DF5EF
3 changed files with 25 additions and 15 deletions

View File

@ -65,18 +65,6 @@ object MainLoop {
val newLogging = state.globalLogging.newLogger(out, logBacking)
transferLevels(state, newLogging)
val loggedState = state.copy(globalLogging = newLogging)
def isInteractive = System.console() != null
def hasShell = state.remainingCommands contains "shell"
/**
* The "boot" command adds "iflast shell" ("if last shell")
* which basically means it falls back to shell if there are no further commands
*/
def endsWithBoot = state.remainingCommands.lastOption exists (_ == "boot")
if (isInteractive && !hasShell && !endsWithBoot) {
state.log warn "Executing in batch mode."
state.log warn " For better performance, hit [ENTER] to switch to interactive mode, or"
state.log warn " consider launching sbt without any commands, or explicitly passing 'shell'"
}
try run(loggedState) finally out.close()
}

View File

@ -5,6 +5,7 @@ package sbt
import java.io.File
import java.util.concurrent.Callable
import sbt.BasicCommandStrings.Shell
/**
* Data structure representing all command execution information.
@ -183,8 +184,9 @@ object State {
}
def isInteractive = System.console() != null
def hasInput = System.console().reader().ready()
def hasShellCmd = s.definedCommands exists { case c: SimpleCommand => c.name == Shell; case _ => false }
s.remainingCommands match {
case Seq() => if (isInteractive && hasInput) doX("shell", Nil) else exit(true)
case Seq() => if (isInteractive && hasInput && hasShellCmd) doX(Shell, Nil) else exit(true)
case Seq(x, xs @ _*) => doX(x, xs)
}
}

View File

@ -18,6 +18,9 @@ import java.net.URI
import java.util.Locale
import scala.util.control.NonFatal
import BasicCommandStrings.Shell
import CommandStrings.BootCommand
/** This class is the entry point for sbt. */
final class xMain extends xsbti.AppMain {
def run(configuration: xsbti.AppConfiguration): xsbti.MainResult =
@ -28,10 +31,11 @@ final class xMain extends xsbti.AppMain {
import CommandStrings.{ BootCommand, DefaultsCommand, InitCommand }
if (!java.lang.Boolean.getBoolean("sbt.skip.version.write"))
setSbtVersion(configuration.baseDirectory(), configuration.provider().id().version())
runManaged(initialState(configuration,
val state = initialState(configuration,
Seq(defaults, early),
runEarly(DefaultsCommand) :: runEarly(InitCommand) :: BootCommand :: Nil)
)
notifyUsersAboutShell(state)
runManaged(state)
}
private val sbtVersionRegex = """sbt\.version\s*=.*""".r
@ -62,6 +66,22 @@ final class xMain extends xsbti.AppMain {
}
}
}
private def isInteractive = System.console() != null
private def hasShell(state: State) = state.remainingCommands contains Shell
/**
* The "boot" command adds "iflast shell" ("if last shell")
* which basically means it falls back to shell if there are no further commands
*/
private def endsWithBoot(state: State) = state.remainingCommands.lastOption exists (_ == BootCommand)
private def notifyUsersAboutShell(state: State) =
if (isInteractive && !hasShell(state) && !endsWithBoot(state)) {
state.log warn "Executing in batch mode."
state.log warn " For better performance, hit [ENTER] to switch to interactive mode, or"
state.log warn " consider launching sbt without any commands, or explicitly passing 'shell'"
}
}
final class ScriptMain extends xsbti.AppMain {