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

This commit is contained in:
Mark Harrah 2013-04-30 18:55:02 -04:00
parent 8813712c60
commit 6a70b9f565
6 changed files with 24 additions and 3 deletions

View File

@ -110,6 +110,9 @@ AliasCommand + """ name=
def Shell = "shell"
def ShellDetailed = "Provides an interactive prompt from which commands can be run."
def StashOnFailure = "sbtStashOnFailure"
def PopOnFailure = "sbtPopOnFailure"
def ClearOnFailure = "--"
def OnFailure = "-"
def OnFailureDetailed =

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))
def stashOnFailure = Command.command(StashOnFailure)(s => s.copy(onFailure = None).update(OnFailureStack)(s.onFailure :: _.toList.flatten))
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.flatten)
}
def reboot = Command(RebootCommand, Help.more(RebootCommand, RebootDetailed))(rebootParser) { (s, full) =>
s.reboot(full)

View File

@ -9,4 +9,5 @@ object BasicKeys
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 classLoaderCache = AttributeKey[classpath.ClassLoaderCache]("class-loader-cache", "Caches class loaders based on the classpath entries and last modified times.", 10)
private[sbt] val OnFailureStack = AttributeKey[List[Option[String]]]("on-failure-stack", "Stack that remembers on-failure handlers.", 10)
}

View File

@ -121,6 +121,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.*/

View File

@ -77,7 +77,8 @@ 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, export, boot, nop, call, exit, act)
setOnFailure, clearOnFailure, stashOnFailure, popOnFailure,
ifLast, multi, shell, continuous, eval, alias, append, last, lastGrep, export, boot, nop, call, exit, act)
def DefaultBootCommands: Seq[String] = LoadProject :: (IfLast + " " + Shell) :: Nil
def boot = Command.make(BootCommand)(bootParser)
@ -415,7 +416,13 @@ object BuiltinCommands
}
}
def loadProjectCommands(arg: String) = (OnFailure + " " + LoadFailed) :: (LoadProjectImpl + " " + arg).trim :: ClearOnFailure :: State.FailureWall :: Nil
def loadProjectCommands(arg: String) =
StashOnFailure ::
(OnFailure + " " + LoadFailed) ::
(LoadProjectImpl + " " + arg).trim ::
PopOnFailure ::
State.FailureWall ::
Nil
def loadProject = Command(LoadProject, LoadProjectBrief, LoadProjectDetailed)(_ => matched(Project.loadActionParser)) { (s,arg) => loadProjectCommands(arg) ::: s }
def loadProjectImpl = Command(LoadProjectImpl)(_ => Project.loadActionParser)( doLoadProject )

View File

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