Proper support for stashing on-failure handlers. Fixes #732.

This commit is contained in:
Mark Harrah
2013-05-31 10:35:47 -04:00
parent f36f59d281
commit c232e344ff
6 changed files with 24 additions and 3 deletions
+9 -2
View File
@@ -62,6 +62,7 @@ object StandardMain
import DefaultParsers._
import CommandStrings._
import BasicCommandStrings.{StashOnFailure, PopOnFailure}
import BasicCommands._
import CommandUtil._
@@ -73,7 +74,7 @@ object BuiltinCommands
def ScriptCommands: Seq[Command] = Seq(ignore, exit, Script.command, act, nop)
def DefaultCommands: Seq[Command] = Seq(ignore, help, about, tasks, settingsCommand, loadProject,
projects, project, reboot, read, history, set, sessionCommand, inspect, loadProjectImpl, loadFailed, Cross.crossBuild, Cross.switchVersion,
setOnFailure, clearOnFailure, ifLast, multi, shell, continuous, eval, alias, append, last, lastGrep, boot, nop, call, exit, act)
setOnFailure, clearOnFailure, stashOnFailure, popOnFailure, ifLast, multi, shell, continuous, eval, alias, append, last, lastGrep, boot, nop, call, exit, act)
def DefaultBootCommands: Seq[String] = LoadProject :: (IfLast + " " + Shell) :: Nil
def boot = Command.make(BootCommand)(bootParser)
@@ -395,7 +396,13 @@ object BuiltinCommands
}
}
def loadProjectCommands(arg: String) = (OnFailure + " " + LoadFailed) :: (LoadProjectImpl + " " + arg).trim :: ClearOnFailure :: FailureWall :: Nil
def loadProjectCommands(arg: String): List[String] =
StashOnFailure ::
(OnFailure + " " + LoadFailed) ::
(LoadProjectImpl + " " + arg).trim ::
PopOnFailure ::
FailureWall ::
Nil
def loadProject = Command(LoadProject, LoadProjectBrief, LoadProjectDetailed)(_ => matched(Project.loadActionParser)) { (s,arg) => loadProjectCommands(arg) ::: s }
def loadProjectImpl = Command(LoadProjectImpl)(_ => Project.loadActionParser)( doLoadProject )
+3
View File
@@ -110,6 +110,9 @@ AliasCommand + """ name=
def Shell = "shell"
def ShellDetailed = "Provides an interactive prompt from which commands can be run."
private[sbt] def StashOnFailure = "sbtStashOnFailure"
private[sbt] def PopOnFailure = "sbtPopOnFailure"
def ClearOnFailure = "--"
def OnFailure = "-"
def OnFailureDetailed =
+7 -1
View File
@@ -16,7 +16,7 @@ package sbt
object BasicCommands
{
lazy val allBasicCommands = Seq(nop, ignore, help, multi, ifLast, append, setOnFailure, clearOnFailure, reboot, call, exit, continuous, history, shell, read, alias)
lazy val allBasicCommands = Seq(nop, ignore, help, multi, ifLast, append, setOnFailure, clearOnFailure, stashOnFailure, popOnFailure, reboot, call, exit, continuous, history, shell, read, alias)
def nop = Command.custom(s => success(() => s))
def ignore = Command.command(FailureWall)(idFun)
@@ -74,6 +74,12 @@ object BasicCommands
s.copy(onFailure = Some(arg))
}
def clearOnFailure = Command.command(ClearOnFailure)(s => s.copy(onFailure = None))
private[sbt] def stashOnFailure = Command.command(StashOnFailure)(s => s.copy(onFailure = None).update(OnFailureStack)(s.onFailure :: _.toList.flatten))
private[sbt] def popOnFailure = Command.command(PopOnFailure) { s =>
val stack = s.get(OnFailureStack).getOrElse(Nil)
val updated = if(stack.isEmpty) s.remove(OnFailureStack) else s.put(OnFailureStack, stack.tail)
updated.copy(onFailure = stack.headOption.flatMap(idFun))
}
def reboot = Command(RebootCommand, Help.more(RebootCommand, RebootDetailed))(rebootParser) { (s, full) =>
s.reboot(full)
+1
View File
@@ -8,4 +8,5 @@ object BasicKeys
val shellPrompt = AttributeKey[State => String]("shell-prompt", "The function that constructs the command prompt from the current build state.", 10000)
val watch = AttributeKey[Watched]("watch", "Continuous execution configuration.", 1000)
private[sbt] val interactive = AttributeKey[Boolean]("interactive", "True if commands are currently being entered from an interactive environment.", 10)
private[sbt] val OnFailureStack = AttributeKey[List[Option[String]]]("on-failure-stack", "Stack that remembers on-failure handlers.", 10)
}
+1
View File
@@ -119,6 +119,7 @@ trait StateOps {
object State
{
/** Indicates where command execution should resume after a failure.*/
final val FailureWall = "---"
/** Represents the next action for the command processor.*/
@@ -0,0 +1,3 @@
# Issue 732: reload followed by a command that results in an error exits in interactive mode
-> ;reload;not-a-command
> help