【发布时间】:2014-09-01 07:36:29
【问题描述】:
我在http://www.scala-sbt.org/0.13/docs/Input-Tasks.html 找到的文档完全令人费解。有人可以为我提供一个任务/输入任务的完整示例,它接受命令行参数并对其进行处理,例如:
sbt "greeting hello world"
并打印“hello world”
【问题讨论】:
我在http://www.scala-sbt.org/0.13/docs/Input-Tasks.html 找到的文档完全令人费解。有人可以为我提供一个任务/输入任务的完整示例,它接受命令行参数并对其进行处理,例如:
sbt "greeting hello world"
并打印“hello world”
【问题讨论】:
跟随文档Input Tasks(主要更改了输入任务的名称,因此它是greeting):
import sbt.complete.Parsers.spaceDelimited
val greeting = inputKey[Unit]("A demo input task.")
greeting := {
val args: Seq[String] = spaceDelimited("<arg>").parsed
args foreach println
}
通过build.sbt中的上述内容,您可以从控制台调用输入任务:
> greeting "hello world"
hello world
或从命令行:
➜ so-25596401 xsbt 'greeting "hello world"'
[info] Loading global plugins from /Users/jacek/.sbt/0.13/plugins
[info] Set current project to so-25596401 (in build file:/Users/jacek/sandbox/so-25596401/)
hello world
[success] Total time: 0 s, completed Sep 1, 2014 1:34:31 AM
注意用引号指定什么是带有参数的单个任务/命令。
【讨论】: