mirror of https://github.com/sbt/sbt.git
Move setting query things into SettingQuery
This commit is contained in:
parent
8081661a7d
commit
4566c615c7
|
|
@ -79,32 +79,8 @@ final class NetworkChannel(val name: String, connection: Socket, structure: Buil
|
||||||
private def onExecCommand(cmd: ExecCommand) =
|
private def onExecCommand(cmd: ExecCommand) =
|
||||||
append(Exec(cmd.commandLine, cmd.execId orElse Some(Exec.newExecId), Some(CommandSource(name))))
|
append(Exec(cmd.commandLine, cmd.execId orElse Some(Exec.newExecId), Some(CommandSource(name))))
|
||||||
|
|
||||||
private def onSettingQuery(req: SettingQuery) = {
|
private def onSettingQuery(req: SettingQuery) =
|
||||||
import sbt.internal.util.complete.Parser
|
StandardMain.exchange publishEventMessage SettingQuery.handleSettingQuery(req, structure, currentBuild)
|
||||||
|
|
||||||
val key = Parser.parse(req.setting, SettingQuery.scopedKeyParser(structure, currentBuild))
|
|
||||||
|
|
||||||
def getSettingValue[A](key: Def.ScopedKey[A]): Either[String, A] =
|
|
||||||
structure.data.get(key.scope, key.key)
|
|
||||||
.toRight(s"Key ${Def displayFull key} not found")
|
|
||||||
.flatMap {
|
|
||||||
case _: Task[_] => Left(s"Key ${Def displayFull key} is a task, can only query settings")
|
|
||||||
case _: InputTask[_] => Left(s"Key ${Def displayFull key} is an input task, can only query settings")
|
|
||||||
case x => Right(x)
|
|
||||||
}
|
|
||||||
|
|
||||||
val values: Either[String, Any] = key match {
|
|
||||||
case Left(msg) => Left(s"Invalid programmatic input: $msg")
|
|
||||||
case Right(key) => getSettingValue(key)
|
|
||||||
}
|
|
||||||
|
|
||||||
val jsonValues: String = values match {
|
|
||||||
case Left(errors) => errors
|
|
||||||
case Right(value) => value.toString
|
|
||||||
}
|
|
||||||
|
|
||||||
StandardMain.exchange publishEventMessage SettingQueryResponse(jsonValues)
|
|
||||||
}
|
|
||||||
|
|
||||||
def shutdown(): Unit = {
|
def shutdown(): Unit = {
|
||||||
println("Shutting down client connection")
|
println("Shutting down client connection")
|
||||||
|
|
@ -178,4 +154,29 @@ object SettingQuery {
|
||||||
structure.index.keyMap,
|
structure.index.keyMap,
|
||||||
structure.data
|
structure.data
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def handleSettingQuery(req: SettingQuery, structure: BuildStructure, currentBuild: URI): SettingQueryResponse = {
|
||||||
|
val key = Parser.parse(req.setting, scopedKeyParser(structure, currentBuild))
|
||||||
|
|
||||||
|
def getSettingValue[A](key: Def.ScopedKey[A]): Either[String, A] =
|
||||||
|
structure.data.get(key.scope, key.key)
|
||||||
|
.toRight(s"Key ${Def displayFull key} not found")
|
||||||
|
.flatMap {
|
||||||
|
case _: Task[_] => Left(s"Key ${Def displayFull key} is a task, can only query settings")
|
||||||
|
case _: InputTask[_] => Left(s"Key ${Def displayFull key} is an input task, can only query settings")
|
||||||
|
case x => Right(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
val values: Either[String, Any] = key match {
|
||||||
|
case Left(msg) => Left(s"Invalid programmatic input: $msg")
|
||||||
|
case Right(key) => getSettingValue(key)
|
||||||
|
}
|
||||||
|
|
||||||
|
val jsonValues: String = values match {
|
||||||
|
case Left(errors) => errors
|
||||||
|
case Right(value) => value.toString
|
||||||
|
}
|
||||||
|
|
||||||
|
SettingQueryResponse(jsonValues)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue