delegates command

This commit is contained in:
Mark Harrah 2011-02-06 12:26:20 -05:00
parent 06a346a543
commit b9b607aade
2 changed files with 36 additions and 14 deletions

View File

@ -41,13 +41,26 @@ EvalCommand + """ <expression>
Evaluates the given Scala expression and prints the result and type. Evaluates the given Scala expression and prints the result and type.
""" """
val GetCommand = "get" def DelegatesCommand = "delegates"
val getBrief = (GetCommand + " <setting-key>", "Prints the value for the given key.") def delegatesBrief = (DelegatesCommand + " <key>", "Prints the scopes searched when resolving the given key.")
val getDetailed = def delegatesDetailed =
GetCommand + """ <setting-key> DelegatesCommand + """ <key>
<key> is interpreted as a Scala expression of type sbt.Scoped.
When a key is resolved to a value, it may not be defined in the requested scope.
In this case, there is a defined search sequence.
This command prints the scopes that are searched for the key.
"""
Displays the value bound to the key argument using its toString method. val GetCommand = "get"
<setting-key> is interpreted as a Scala expression of type sbt.ScopedSetting[_]. val getBrief = (GetCommand + " <key>", "Prints the value for the given key, the defining scope, related definitions, and dependencies.")
val getDetailed =
GetCommand + """ <key>
<key> is interpreted as a Scala expression of type sbt.Scoped.
For a plain setting, the value bound to the key argument is displayed using its toString method.
Otherwise, the type of task ("Task" or "Input task") is displayed.
Other details are shown, including the defining scope, dependencies, and related definitions.
""" """
val SetCommand = "set" val SetCommand = "set"

View File

@ -59,7 +59,7 @@ class xMain extends xsbti.AppMain
object Commands object Commands
{ {
def DefaultCommands: Seq[Command] = Seq(ignore, help, reload, read, history, continuous, exit, loadCommands, loadProject, compile, discover, def DefaultCommands: Seq[Command] = Seq(ignore, help, reload, read, history, continuous, exit, loadCommands, loadProject, compile, discover,
projects, project, setOnFailure, ifLast, multi, shell, set, get, eval, alias, append, nop, sessionCommand, act) projects, project, setOnFailure, ifLast, multi, shell, set, get, eval, delegates,alias, append, nop, sessionCommand, act)
def nop = Command.custom(s => success(() => s), Nil) def nop = Command.custom(s => success(() => s), Nil)
def ignore = Command.command(FailureWall)(identity) def ignore = Command.command(FailureWall)(identity)
@ -235,15 +235,24 @@ object Commands
val newSession = session.appendSettings( append map (a => (a, arg))) val newSession = session.appendSettings( append map (a => (a, arg)))
reapply(newSession, structure, s) reapply(newSession, structure, s)
} }
def get = Command.single(GetCommand, getBrief, getDetailed) { (s, arg) => def get = Command.single(GetCommand, getBrief, getDetailed)( scopedCommand(GetCommand) { (s, scope, key, structure) =>
val extracted = Project extract s val detailString = Project.details(structure, scope, key)
import extracted._
val result = session.currentEval().eval(arg, srcName = "get", imports = autoImports(extracted), tpeName = Some("sbt.Scoped"))
val scoped = result.value.asInstanceOf[Scoped]
val resolve = Scope.resolveScope(Load.projectScope(curi, cid), curi, rootProject)
val detailString = Project.details(structure, resolve(scoped.scope), scoped.key)
logger(s).info(detailString) logger(s).info(detailString)
s s
})
def delegates = Command.single(DelegatesCommand, delegatesBrief, delegatesDetailed) ( scopedCommand(DelegatesCommand) { (s, scope, key, structure) =>
val log = logger(s)
structure.delegates(scope).foreach(d => log.info(Project.display(Project.ScopedKey(d, key))))
s
})
def scopedCommand(srcName: String)(f: (State, Scope, AttributeKey[_], Load.BuildStructure) => State): (State, String) => State = (s, arg) =>
{
val extracted = Project extract s
import extracted._
val result = session.currentEval().eval(arg, srcName = srcName, imports = autoImports(extracted), tpeName = Some("sbt.Scoped"))
val scoped = result.value.asInstanceOf[Scoped]
val resolve = Scope.resolveScope(Load.projectScope(curi, cid), curi, rootProject)
f(s, resolve(scoped.scope), scoped.key, structure)
} }
def autoImports(extracted: Extracted): EvalImports = new EvalImports(imports(extracted), "<auto-imports>") def autoImports(extracted: Extracted): EvalImports = new EvalImports(imports(extracted), "<auto-imports>")
def imports(extracted: Extracted): Seq[(String,Int)] = def imports(extracted: Extracted): Seq[(String,Int)] =