Given I have
build.sbt
name := """app"""
version := "1.0-SNAPSHOT"
lazy val root = (project in file(".")).enablePlugins(PlayScala)
scalaVersion := "2.11.7"
// <-- some other code -->
import Fixtures._
lazy val fixtures = inputKey[Unit]("Generating Cassandra fixtures")
fixtures := {
Fixtures.generate()
}
project
object Fixtures {
def generate (): Unit = {
println("generating fixtures")
}
}
./activator fixtures
GenerateUserFixtureService.scala
app/scala/com/MyProject/Service
project
Fixtures.scala
|
|___app
| |__scala
| |__com
| |__MyProject
| |__Service
| |--GenerateUserFixtureService.scala
|___project
| |--Fixtures.scala
|___
|--build.sbt
build.sbt
project
app
upload:fixtures
send:emails
For creating a custom command you must specify a function which corresponds to the logic of your command. Let's consider a few examples: first just print hello message:
def helloSbt = Command.command("hello") { state =>
println("Hello, SBT")
state
}
commands += helloSbt
just put this code into build.sbt
, commands
is project key
which is present into sbt.Keys
as val commands = SettingKey[Seq[Command]]
Of course, you can manage the statement of your command like success or fail:
def failJustForFun = Command.single("fail-condidtion") {
case (state, "true") => state.fail
case (state, _) => state
}
You can change the color in console for specific part of your command or output of this command via leveraging of DefaultParsers
:
lazy val color = token( Space ~> ("blue" ^^^ "4" | "green" ^^^ "2") )
lazy val select = token( "fg" ^^^ "3" | "bg" ^^^ "4" )
lazy val setColor = (select ~ color) map { case (g, c) => "\033[" + g + c + "m" }
And like alternative, you can extend xsbti.AppMain
and implement - your own logic