mirror of https://github.com/sbt/sbt.git
Allow aliases to be used in continuous builds
@japgolly reported in #4695 that aliased commands don't work in watch anymore. This was because we were extracting the task from the raw command rather than the aliased command. Since the alias wasn't a valid key, we weren't able to parse the scoped key. The fix is to find the aliased value and try that if we fail to parse the original command. Fixes #4695
This commit is contained in:
parent
aefd0969b1
commit
f7dd228808
|
|
@ -380,12 +380,21 @@ private[sbt] object Continuous extends DeprecatedContinuous {
|
|||
// We have to add the <~ Parsers.any.* to ensure that we're able to extract the input key
|
||||
// from input tasks.
|
||||
val scopedKeyParser: Parser[Seq[ScopedKey[_]]] = Act.aggregatedKeyParser(state) <~ Parsers.any.*
|
||||
Parser.parse(command, scopedKeyParser) match {
|
||||
case Right(scopedKeys: Seq[ScopedKey[_]]) => scopedKeys
|
||||
case Left(e) =>
|
||||
throw new IllegalStateException(s"Error attempting to extract scope from $command: $e.")
|
||||
case _ => Nil: Seq[ScopedKey[_]]
|
||||
@tailrec def impl(current: String): Seq[ScopedKey[_]] = {
|
||||
Parser.parse(current, scopedKeyParser) match {
|
||||
case Right(scopedKeys: Seq[ScopedKey[_]]) => scopedKeys
|
||||
case Left(e) =>
|
||||
val aliases = BasicCommands.allAliases(state)
|
||||
aliases.collectFirst { case (`command`, aliased) => aliased } match {
|
||||
case Some(aliased) => impl(aliased)
|
||||
case _ =>
|
||||
val msg = s"Error attempting to extract scope from $command: $e."
|
||||
throw new IllegalStateException(msg)
|
||||
}
|
||||
case _ => Nil: Seq[ScopedKey[_]]
|
||||
}
|
||||
}
|
||||
impl(command)
|
||||
}
|
||||
|
||||
private def getAllConfigs(
|
||||
|
|
|
|||
|
|
@ -0,0 +1,6 @@
|
|||
val foo = taskKey[Unit]("foo")
|
||||
foo := println("foo")
|
||||
|
||||
foo / watchOnIteration := { _ => sbt.nio.Watch.CancelWatch }
|
||||
addCommandAlias("bar", "foo")
|
||||
addCommandAlias("baz", "foo")
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
> ~bar
|
||||
|
||||
> ~baz
|
||||
Loading…
Reference in New Issue