您可以在命令中访问 SBT SettingKey 吗?

Can you access a SBT SettingKey inside a Command?

我正在编写命令并想在 TaskStreams 中使用 Logger 但这不可能,因为您无法在命令中访问 SettingKey 的 .value。有什么办法吗?

def myCommand = Command.single("myCommand") {
  case (currentState, userInput) =>
    val extracted = Project.extract(currentState)
    val log = streams.value.log   <--- not allowed
    log.info("Some logging")
    currentState
}

streams 用于任务,而不是命令。

所以一种方法是创建一个 "holder" TaskKey 并获取其中的一个流,例如 sbt-pgp creates and uses pgpCmdContext - see the definition of pgp-cmd.


另一种方法是使用sLog,但我不确定这里是否应该使用sLog

val myCommand = Command.single("myCommand") { case (s, arg) =>
  val extracted = Project extract s
  val log = extracted get sLog
  log info "Some logging"
  currentState
}