本文介绍了您可以在命令中访问 SBT SettingKey 吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在编写一个命令并想在 TaskStreams
中使用 Logger
但这不可能,因为您无法访问一个命令的 .value
命令中的设置键.有什么办法吗?
I am writing a Command and want to use the Logger
in TaskStreams
but this is not possible since you cannot access .value
of a SettingKey in a Command. Is there some way?
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
用于任务,而不是命令.
streams
is intended for tasks, not commands.
所以一种方法是创建一个持有者"TaskKey
并获得一个流,例如 sbt-pgp 创建和使用 pgpCmdContext
- 参见 pgp-cmd.
So one way is to create a "holder" TaskKey
and get a stream of that, for instance sbt-pgp creates and uses pgpCmdContext
- see the definition of pgp-cmd.
另一种方法是使用 sLog
,但我不确定这里是否应该使用 sLog
:
Another way is using sLog
, but I'm not sure if sLog
should be used here:
val myCommand = Command.single("myCommand") { case (s, arg) =>
val extracted = Project extract s
val log = extracted get sLog
log info "Some logging"
currentState
}
这篇关于您可以在命令中访问 SBT SettingKey 吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!