Created
July 30, 2021 03:43
-
-
Save xuwei-k/804204886346ffd5ba4b51343dc2fd5a to your computer and use it in GitHub Desktop.
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("taskAll")) ~> Space.string ~> NotSpace.examples(suggestionTasks) ~ distinctParser(getProjects(s).toSet) | |
} { case (s, (taskName: String, projectRegexList: Seq[String])) => | |
println((taskName, projectRegexList)) | |
val projects = getProjects(s).filter{ id => | |
projectRegexList.exists(r => id.matches(r) || id.startsWith(r)) | |
} | |
if (projects.nonEmpty) { | |
val result = projects.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