當前執行此操作的最佳方法是直接實施自定義任務。詳情請參閱Input Tasks。
// A custom task is required because `test` doesn't accept input.
lazy val customTest = inputKey[Unit]("custom test")
// This custom parser accepts a space separated list of arguments and then appends
// the fixed arguments to them. To do further parsing based on the user-specified
// arguments, use `flatMap` and return the next Parser.
lazy val testParser =
Def.spaceDelimited().map((explicitArgs: Seq[String]) =>
explicitArgs ++ Seq("--bar", "--baz", "--qux", "--quux", "someDirectory")
)
customTest := {
// the result of parsing
val args = testParser.parsed
// auto-detected main class: can replace with literal string
val main = (mainClass in Compile).value getOrElse error("No main class detected.")
// main classpath, including compiled classes
val classpath = (fullClasspath in Compile).value.files
// provides Scala code execution
val scalaRun = (runner in (Compile, run)).value
val result = scalaRun.run(main, classpath, args, streams.value.log)
// handle any error
result foreach { errorMsg => sys.error(errorMsg) }
}
是對'測試foo'有意擴展爲'跑富--bar ...'或者是隻是一個速記,你仍然預計全'測試富--bar ...'? –
前者 - 默認情況下,我想擴展到完整列表。但是,指定選項以允許「高級」用戶選擇除默認值之外的其他選項將會很好。 – dan