diff --git a/main/Main.scala b/main/Main.scala index 3940789c9..d1b11d51a 100644 --- a/main/Main.scala +++ b/main/Main.scala @@ -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 ) diff --git a/main/command/BasicCommandStrings.scala b/main/command/BasicCommandStrings.scala index fa6fc4b5d..dae3814d7 100644 --- a/main/command/BasicCommandStrings.scala +++ b/main/command/BasicCommandStrings.scala @@ -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 = diff --git a/main/command/BasicCommands.scala b/main/command/BasicCommands.scala index 617c6f7ae..69fc06e7d 100644 --- a/main/command/BasicCommands.scala +++ b/main/command/BasicCommands.scala @@ -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) diff --git a/main/command/BasicKeys.scala b/main/command/BasicKeys.scala index 80409672c..2dd6e17e2 100644 --- a/main/command/BasicKeys.scala +++ b/main/command/BasicKeys.scala @@ -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) } diff --git a/main/command/State.scala b/main/command/State.scala index f7f9310a0..6b00a5a6e 100644 --- a/main/command/State.scala +++ b/main/command/State.scala @@ -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.*/ diff --git a/sbt/src/sbt-test/actions/multiple-with-error/test b/sbt/src/sbt-test/actions/multiple-with-error/test new file mode 100644 index 000000000..ff83f1b3d --- /dev/null +++ b/sbt/src/sbt-test/actions/multiple-with-error/test @@ -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