Skip to content

Commit

Permalink
addCommandAlias method for defining command aliases in build definiti…
Browse files Browse the repository at this point in the history
…ons. fixes #388
  • Loading branch information
harrah committed Mar 5, 2012
1 parent 868196e commit 6746557
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 0 deletions.
12 changes: 12 additions & 0 deletions main/Defaults.scala
Expand Up @@ -1139,6 +1139,18 @@ trait BuildExtra extends BuildCommon
{
import Defaults._

/** Defines an alias given by `name` that expands to `value`.
* This alias is defined globally after projects are loaded.
* The alias is undefined when projects are unloaded.
* Names are restricted to be either alphanumeric or completely symbolic.
* As an exception, '-' and '_' are allowed within an alphanumeric name.*/
def addCommandAlias(name: String, value: String): Seq[Setting[State => State]] =
{
val add = (s: State) => BasicCommands.addAlias(s, name, value)
val remove = (s: State) => BasicCommands.removeAlias(s, name)
def compose(setting: SettingKey[State => State], f: State => State) = setting in Global ~= (_ compose f)
Seq( compose(onLoad, add), compose(onUnload, remove) )
}
def addSbtPlugin(dependency: ModuleID): Setting[Seq[ModuleID]] =
libraryDependencies <+= (sbtBinaryVersion in update,scalaBinaryVersion in update) { (sbtV, scalaV) => sbtPluginExtra(dependency, sbtV, scalaV) }

Expand Down
3 changes: 3 additions & 0 deletions sbt/src/sbt-test/actions/add-alias/A.scala
@@ -0,0 +1,3 @@
object A extends App {
if(args(0).toBoolean) () else error("Fail")
}
2 changes: 2 additions & 0 deletions sbt/src/sbt-test/actions/add-alias/build.sbt
@@ -0,0 +1,2 @@
addCommandAlias("demo-success", "run true") ++
addCommandAlias("demo-failure", "run false")
2 changes: 2 additions & 0 deletions sbt/src/sbt-test/actions/add-alias/test
@@ -0,0 +1,2 @@
> demo-success
-> demo-failure

0 comments on commit 6746557

Please sign in to comment.