Skip to content

Instantly share code, notes, and snippets.

@sjednac
Created September 14, 2017 08:11
Show Gist options
  • Save sjednac/90b2737842880fbc5e9ef0fa89c9ca29 to your computer and use it in GitHub Desktop.
Save sjednac/90b2737842880fbc5e9ef0fa89c9ca29 to your computer and use it in GitHub Desktop.
Override a task setting in an SBT command
lazy val person = settingKey[String]("Person to greet")
lazy val hello = taskKey[Unit]("Greet person")
// https://stackoverflow.com/q/14262798/1535738
def greetEveryone = Command.command("greetEveryone") { state =>
Seq("John", "Alice", "Bob").foreach { name =>
val extracted = Project extract state
val newState = extracted.append(Seq(person := name), state)
Project.extract(newState).runTask(hello, newState)
}
state
}
lazy val root = (project in file("."))
.settings(
person := "John",
hello := {
println(s"Hello ${person.value}")
},
commands ++= Seq(greetEveryone)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment