Merge pull request #3094 from eed3si9n/fport/3035

[fport] Notify about shell less
This commit is contained in:
eugene yokota 2017-04-12 05:46:30 -04:00 committed by GitHub
commit d2e7207299
3 changed files with 27 additions and 18 deletions

View File

@ -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)
}
}

View File

@ -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 {

View File

@ -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()
}