在 play sbt 项目中访问命令行参数
Accessing command line arguments in play sbt project
情况是这样的;我有一个与激活器集成的播放应用程序。为了 运行 我的 G运行t 任务,我将 Grunt.scala 添加到我的项目
import java.net.InetSocketAddress
import play.sbt.PlayRunHook
import sbt._
object Grunt {
def apply(base: File): PlayRunHook = {
object GruntProcess extends PlayRunHook {
var process: Option[Process] = None
def osCommand(command: String): String = {
System.getProperty("os.name").toLowerCase().startsWith("win") match{
case true => s"cmd.exe /c $command"
case false => command
}
}
override def beforeStarted(): Unit = {
Process(osCommand("grunt dist"), base).run
}
override def afterStarted(addr: InetSocketAddress): Unit = {
process = Some(Process(osCommand("grunt watch"), base).run)
}
override def afterStopped(): Unit = {
process.map(p => p.destroy())
process = None
}
}
GruntProcess
}
}
然后将以下行添加到我的 build.sbt 中:
PlayKeys.playRunHooks += Grunt(baseDirectory.value)
基本上是按照Play的文档来的。所以现在为了 运行 我的项目,我使用以下激活命令:
activator -Dsbt.log.noformat=true clean dist universal:packageZipTarball
问题是如何从 Scala class 访问 "dist" 命令行参数。我想使用该参数来确定我应该 运行.
哪个 G运行t 任务(dist、test 等)
我发现 this 存储库中的 SBT 文件很有教育意义。正如您在该文件底部看到的那样,基本上从 SBT 文件(不是 scala 钩子)处理不同的环境:
....
// Execute frontend prod build task prior to play dist execution.
dist := (dist dependsOn `ui-prod-build`).value
// Execute frontend prod build task prior to play stage execution.
stage := (stage dependsOn `ui-prod-build`).value
....
情况是这样的;我有一个与激活器集成的播放应用程序。为了 运行 我的 G运行t 任务,我将 Grunt.scala 添加到我的项目
import java.net.InetSocketAddress
import play.sbt.PlayRunHook
import sbt._
object Grunt {
def apply(base: File): PlayRunHook = {
object GruntProcess extends PlayRunHook {
var process: Option[Process] = None
def osCommand(command: String): String = {
System.getProperty("os.name").toLowerCase().startsWith("win") match{
case true => s"cmd.exe /c $command"
case false => command
}
}
override def beforeStarted(): Unit = {
Process(osCommand("grunt dist"), base).run
}
override def afterStarted(addr: InetSocketAddress): Unit = {
process = Some(Process(osCommand("grunt watch"), base).run)
}
override def afterStopped(): Unit = {
process.map(p => p.destroy())
process = None
}
}
GruntProcess
}
}
然后将以下行添加到我的 build.sbt 中:
PlayKeys.playRunHooks += Grunt(baseDirectory.value)
基本上是按照Play的文档来的。所以现在为了 运行 我的项目,我使用以下激活命令:
activator -Dsbt.log.noformat=true clean dist universal:packageZipTarball
问题是如何从 Scala class 访问 "dist" 命令行参数。我想使用该参数来确定我应该 运行.
哪个 G运行t 任务(dist、test 等)我发现 this 存储库中的 SBT 文件很有教育意义。正如您在该文件底部看到的那样,基本上从 SBT 文件(不是 scala 钩子)处理不同的环境:
....
// Execute frontend prod build task prior to play dist execution.
dist := (dist dependsOn `ui-prod-build`).value
// Execute frontend prod build task prior to play stage execution.
stage := (stage dependsOn `ui-prod-build`).value
....