From 881cb4246a36cad7ef6cb81c113351327f1802ad Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Tue, 21 Mar 2017 13:08:47 +0000 Subject: [PATCH] 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 --- main-command/src/main/scala/sbt/State.scala | 4 ++- main/src/main/scala/sbt/Main.scala | 28 ++++++++++++++++++--- main/src/main/scala/sbt/MainLoop.scala | 13 ---------- 3 files changed, 27 insertions(+), 18 deletions(-) diff --git a/main-command/src/main/scala/sbt/State.scala b/main-command/src/main/scala/sbt/State.scala index e76546533..9bbcb673a 100644 --- a/main-command/src/main/scala/sbt/State.scala +++ b/main-command/src/main/scala/sbt/State.scala @@ -9,6 +9,7 @@ import sbt.util.Logger import sbt.internal.util.{ AttributeKey, AttributeMap, ErrorHandling, ExitHook, ExitHooks, GlobalLogging } import sbt.internal.util.complete.HistoryCommands import sbt.internal.inc.classpath.ClassLoaderCache +import sbt.BasicCommandStrings.Shell /** * Data structure representing all command execution information. @@ -203,8 +204,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 List() => if (isInteractive && hasInput) doX(Exec("shell", s.source), Nil) else exit(true) + case List() => if (isInteractive && hasInput && hasShellCmd) doX(Exec(Shell, s.source), Nil) else exit(true) case List(x, xs @ _*) => doX(x, xs.toList) } } diff --git a/main/src/main/scala/sbt/Main.scala b/main/src/main/scala/sbt/Main.scala index 977956d70..f68f1e6c5 100644 --- a/main/src/main/scala/sbt/Main.scala +++ b/main/src/main/scala/sbt/Main.scala @@ -44,6 +44,9 @@ import java.net.URI import java.util.Locale import scala.util.control.NonFatal +import BasicCommandStrings.{ Shell, Server } +import CommandStrings.BootCommand + /** This class is the entry point for sbt. */ final class xMain extends xsbti.AppMain { def run(configuration: xsbti.AppConfiguration): xsbti.MainResult = @@ -55,11 +58,11 @@ final class xMain extends xsbti.AppMain { 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 - )) + runEarly(DefaultsCommand) :: runEarly(InitCommand) :: BootCommand :: Nil) + notifyUsersAboutShell(state) + runManaged(state) } private val sbtVersionRegex = """sbt\.version\s*=.*""".r @@ -90,6 +93,23 @@ final class xMain extends xsbti.AppMain { } } } + + private def isInteractive = System.console() != null + private def hasCommand(state: State, cmd: String): Boolean = + (state.remainingCommands find { x => x.commandLine == cmd }).isDefined + + /** + * 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 (_.commandLine == BootCommand) + + private def notifyUsersAboutShell(state: State) = + if (isInteractive && !hasCommand(state, Shell) && !hasCommand(state, Server) && !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 { diff --git a/main/src/main/scala/sbt/MainLoop.scala b/main/src/main/scala/sbt/MainLoop.scala index d4be1d232..f269d571e 100644 --- a/main/src/main/scala/sbt/MainLoop.scala +++ b/main/src/main/scala/sbt/MainLoop.scala @@ -72,19 +72,6 @@ object MainLoop { val newLogging = state.globalLogging.newAppender(full, out, logBacking) // transferLevels(state, newLogging) val loggedState = state.copy(globalLogging = newLogging) - def isInteractive = System.console() != null - def hasCommand(cmd: String): Boolean = - (state.remainingCommands find { x => x.commandLine == cmd }).isDefined - /** - * 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 (_.commandLine == "boot") - if (isInteractive && !hasCommand("shell") && !hasCommand("server") && !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() }