mirror of https://github.com/sbt/sbt.git
Don't require newline for load failed commands
It's a bit annoying to have to hit enter here. Also, this should fix https://github.com/sbt/sbt/issues/5162 because if there is no System.in attached, the read will return -1 which will cause sbt to quit.
This commit is contained in:
parent
c7b52203a0
commit
5afc0f0fdf
|
|
@ -10,9 +10,9 @@ package sbt
|
||||||
import java.io.{ File, IOException }
|
import java.io.{ File, IOException }
|
||||||
import java.net.URI
|
import java.net.URI
|
||||||
import java.nio.file.{ FileAlreadyExistsException, FileSystems, Files }
|
import java.nio.file.{ FileAlreadyExistsException, FileSystems, Files }
|
||||||
|
import java.util.Properties
|
||||||
import java.util.concurrent.ForkJoinPool
|
import java.util.concurrent.ForkJoinPool
|
||||||
import java.util.concurrent.atomic.AtomicBoolean
|
import java.util.concurrent.atomic.AtomicBoolean
|
||||||
import java.util.{ Locale, Properties }
|
|
||||||
|
|
||||||
import sbt.BasicCommandStrings.{ Shell, TemplateCommand }
|
import sbt.BasicCommandStrings.{ Shell, TemplateCommand }
|
||||||
import sbt.Project.LoadAction
|
import sbt.Project.LoadAction
|
||||||
|
|
@ -764,22 +764,24 @@ object BuiltinCommands {
|
||||||
|
|
||||||
@tailrec
|
@tailrec
|
||||||
private[this] def doLoadFailed(s: State, loadArg: String): State = {
|
private[this] def doLoadFailed(s: State, loadArg: String): State = {
|
||||||
val result = (SimpleReader.readLine(
|
s.log.warn("Project loading failed: (r)etry, (q)uit, (l)ast, or (i)gnore? (default: r)")
|
||||||
"Project loading failed: (r)etry, (q)uit, (l)ast, or (i)gnore? (default: r)"
|
val result = Terminal.withRawSystemIn {
|
||||||
) getOrElse Quit)
|
Terminal.withEcho(toggle = true)(Terminal.wrappedSystemIn.read() match {
|
||||||
.toLowerCase(Locale.ENGLISH)
|
case -1 => 'q'.toInt
|
||||||
def matches(s: String) = !result.isEmpty && (s startsWith result)
|
case b => b
|
||||||
def retry = loadProjectCommand(LoadProject, loadArg) :: s.clearGlobalLog
|
})
|
||||||
def ignoreMsg =
|
}
|
||||||
|
def retry: State = loadProjectCommand(LoadProject, loadArg) :: s.clearGlobalLog
|
||||||
|
def ignoreMsg: String =
|
||||||
if (Project.isProjectLoaded(s)) "using previously loaded project" else "no project loaded"
|
if (Project.isProjectLoaded(s)) "using previously loaded project" else "no project loaded"
|
||||||
|
|
||||||
result match {
|
result.toChar match {
|
||||||
case "" => retry
|
case '\n' | '\r' => retry
|
||||||
case _ if matches("retry") => retry
|
case 'r' => retry
|
||||||
case _ if matches(Quit) => s.exit(ok = false)
|
case 'q' => s.exit(ok = false)
|
||||||
case _ if matches("ignore") => s.log.warn(s"Ignoring load failure: $ignoreMsg."); s
|
case 'i' => s.log.warn(s"Ignoring load failure: $ignoreMsg."); s
|
||||||
case _ if matches("last") => LastCommand :: loadProjectCommand(LoadFailed, loadArg) :: s
|
case 'l' => LastCommand :: loadProjectCommand(LoadFailed, loadArg) :: s
|
||||||
case _ => println("Invalid response."); doLoadFailed(s, loadArg)
|
case _ => println("Invalid response."); doLoadFailed(s, loadArg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue