diff --git a/main/command/src/main/scala/sbt/MainLoop.scala b/main/command/src/main/scala/sbt/MainLoop.scala index fa512e8dd..488decab0 100644 --- a/main/command/src/main/scala/sbt/MainLoop.scala +++ b/main/command/src/main/scala/sbt/MainLoop.scala @@ -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() } diff --git a/main/command/src/main/scala/sbt/State.scala b/main/command/src/main/scala/sbt/State.scala index 218e136af..bc79ba7a7 100644 --- a/main/command/src/main/scala/sbt/State.scala +++ b/main/command/src/main/scala/sbt/State.scala @@ -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) } } diff --git a/main/src/main/scala/sbt/Main.scala b/main/src/main/scala/sbt/Main.scala index eee3ef79b..f9baefd0e 100644 --- a/main/src/main/scala/sbt/Main.scala +++ b/main/src/main/scala/sbt/Main.scala @@ -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 {