Set correct action for onTermination callback

This commit is contained in:
friendseeker 2024-10-27 22:43:44 -07:00
parent a46dfc0f4b
commit 6d4d2161b2
No known key found for this signature in database
GPG Key ID: 7DD5039728A27160
1 changed files with 8 additions and 5 deletions

View File

@ -1129,7 +1129,7 @@ private[sbt] object Continuous extends DeprecatedContinuous {
val callbacks: Callbacks, val callbacks: Callbacks,
val dynamicInputs: mutable.Set[DynamicInput], val dynamicInputs: mutable.Set[DynamicInput],
val pending: Boolean, val pending: Boolean,
var failAction: Option[Watch.Action], var terminationAction: Option[Watch.Action],
) { ) {
def this( def this(
count: Int, count: Int,
@ -1162,7 +1162,8 @@ private[sbt] object Continuous extends DeprecatedContinuous {
afterWatch, afterWatch,
callbacks, callbacks,
dynamicInputs, dynamicInputs,
p p,
terminationAction,
) )
private def withCount(c: Int): ContinuousState = private def withCount(c: Int): ContinuousState =
new ContinuousState( new ContinuousState(
@ -1173,7 +1174,8 @@ private[sbt] object Continuous extends DeprecatedContinuous {
afterWatch, afterWatch,
callbacks, callbacks,
dynamicInputs, dynamicInputs,
pending pending,
terminationAction,
) )
} }
} }
@ -1341,12 +1343,13 @@ private[sbt] object ContinuousCommands {
case Watch.Trigger => Right(s"$runWatch ${channel.name}") case Watch.Trigger => Right(s"$runWatch ${channel.name}")
case Watch.Reload => case Watch.Reload =>
val rewatch = s"$ContinuousExecutePrefix ${ws.count} ${cs.commands mkString "; "}" val rewatch = s"$ContinuousExecutePrefix ${ws.count} ${cs.commands mkString "; "}"
cs.terminationAction = Some(Watch.Reload)
stop.map(_ :: "reload" :: rewatch :: Nil mkString "; ") stop.map(_ :: "reload" :: rewatch :: Nil mkString "; ")
case Watch.Prompt => stop.map(_ :: s"$PromptChannel ${channel.name}" :: Nil mkString ";") case Watch.Prompt => stop.map(_ :: s"$PromptChannel ${channel.name}" :: Nil mkString ";")
case Watch.Run(commands) => case Watch.Run(commands) =>
stop.map(_ +: commands.map(_.commandLine).filter(_.nonEmpty) mkString "; ") stop.map(_ +: commands.map(_.commandLine).filter(_.nonEmpty) mkString "; ")
case a @ Watch.HandleError(_) => case a @ Watch.HandleError(_) =>
cs.failAction = Some(a) cs.terminationAction = Some(a)
stop.map(_ :: s"$failWatch ${channel.name}" :: Nil mkString "; ") stop.map(_ :: s"$failWatch ${channel.name}" :: Nil mkString "; ")
case _ => stop case _ => stop
} }
@ -1394,7 +1397,7 @@ private[sbt] object ContinuousCommands {
} }
val commands = cs.commands.mkString("; ") val commands = cs.commands.mkString("; ")
val count = cs.count val count = cs.count
val action = cs.failAction.getOrElse(Watch.CancelWatch) val action = cs.terminationAction.getOrElse(Watch.CancelWatch)
val st = cs.callbacks.onTermination(action, commands, count, newState) val st = cs.callbacks.onTermination(action, commands, count, newState)
if (error) st.fail else st if (error) st.fail else st
case _ => if (error) state.fail else state case _ => if (error) state.fail else state