This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
commands += { | |
def getProjects(s: State): Seq[String] = { | |
val extracted = Project.extract(s) | |
val currentBuildUri = extracted.currentRef.build | |
val buildStructure = extracted.structure | |
val buildUnitsMap = buildStructure.units | |
val currentBuildUnit = buildUnitsMap(currentBuildUri) | |
val projectsMap = currentBuildUnit.defined | |
projectsMap.values.map(_.id).toVector | |
} | |
import sbt.internal.util.complete.DefaultParsers._ | |
import sbt.internal.util.complete.Parser | |
def distinctParser(exs: Set[String]): Parser[Seq[String]] = { | |
val base = token(Space) ~> token(NotSpace examples exs) | |
base.flatMap { ex => | |
val (_, notMatching) = exs.partition(GlobFilter(ex).accept) | |
distinctParser(notMatching).map { result => ex +: result } | |
} ?? Nil | |
} | |
val suggestionTasks = Set("compile", "Test/compile", "test", "scalafmtAll", "clean") | |
Command.arb { s => | |
token(literal("reverseTaskAll")) ~> Space.string ~> NotSpace.examples(suggestionTasks) ~ distinctParser( | |
getProjects(s).toSet | |
) | |
} { | |
case (s, (taskName: String, projectRegexList: Seq[String])) => | |
val projects = getProjects(s).filter { id => | |
projectRegexList.exists(r => id.matches(r) || id.startsWith(r)) | |
} | |
if (projects.nonEmpty) { | |
val currentBuildURI = Project.extract(s).currentRef.build | |
def allDependencies(id: String): Seq[String] = { | |
buildDependencies.value | |
.classpathTransitiveRefs(ProjectRef(currentBuildURI, id)) | |
.map(_.project) | |
} | |
val reverseMap: Map[String, Seq[String]] = getProjects(s) | |
.map(x => x -> allDependencies(x)) | |
.flatMap { case (k, v) => v.map(_ -> k) } | |
.groupBy(_._1) | |
.map { | |
case (k, v) => k -> v.map(_._2) | |
} | |
val all = projects.flatMap(reverseMap).sorted | |
val result = all.map(_ + "/" + taskName).mkString("all ", " ", "") | |
s.log.info(result) | |
result :: s | |
} else { | |
s.log.error(s"no match ${projectRegexList.mkString(" ")}") | |
s | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment