Created
August 29, 2017 16:26
-
-
Save williamho/b175bedb6ad2cdf54bd69b17c6ca9395 to your computer and use it in GitHub Desktop.
Temporarily change an sbt setting and execute task
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val greet = taskKey[Unit]("Says hello to you") | |
// Reverses the value of `name` and calls `greet` | |
val greetReverse = Command.command("greetReverse") { state => | |
val extracted = Project.extract(state) | |
val newState = extracted.append(Seq(name := name.value.reverse), state) | |
Project.runTask(greet, newState) | |
state // Reset the state back to what it was originally | |
} | |
lazy val root = (project in file(".")) | |
.settings( | |
name := "world", | |
commands ++= Seq(greetReverse), | |
greet := { | |
println("Hello " + name.value + "!") | |
} | |
) | |
/** sbt output: | |
* | |
* > greet | |
* Hello world! | |
* > greetReverse | |
* Hello dlrow! | |
* > greet | |
* Hello world! | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment