From b9b607aadea7abb777cdd4da57f6902bdc1d29e7 Mon Sep 17 00:00:00 2001 From: Mark Harrah Date: Sun, 6 Feb 2011 12:26:20 -0500 Subject: [PATCH] delegates command --- main/CommandSupport.scala | 25 +++++++++++++++++++------ main/Main.scala | 25 +++++++++++++++++-------- 2 files changed, 36 insertions(+), 14 deletions(-) diff --git a/main/CommandSupport.scala b/main/CommandSupport.scala index 365cb1349..041ad5869 100644 --- a/main/CommandSupport.scala +++ b/main/CommandSupport.scala @@ -41,13 +41,26 @@ EvalCommand + """ Evaluates the given Scala expression and prints the result and type. """ - val GetCommand = "get" - val getBrief = (GetCommand + " ", "Prints the value for the given key.") - val getDetailed = -GetCommand + """ + def DelegatesCommand = "delegates" + def delegatesBrief = (DelegatesCommand + " ", "Prints the scopes searched when resolving the given key.") + def delegatesDetailed = +DelegatesCommand + """ + 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. - is interpreted as a Scala expression of type sbt.ScopedSetting[_]. + val GetCommand = "get" + val getBrief = (GetCommand + " ", "Prints the value for the given key, the defining scope, related definitions, and dependencies.") + val getDetailed = +GetCommand + """ + + 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" diff --git a/main/Main.scala b/main/Main.scala index e7fa785a7..516aa529a 100644 --- a/main/Main.scala +++ b/main/Main.scala @@ -59,7 +59,7 @@ class xMain extends xsbti.AppMain object Commands { 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 ignore = Command.command(FailureWall)(identity) @@ -235,15 +235,24 @@ object Commands val newSession = session.appendSettings( append map (a => (a, arg))) reapply(newSession, structure, s) } - def get = Command.single(GetCommand, getBrief, getDetailed) { (s, arg) => - val extracted = Project extract s - 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) + def get = Command.single(GetCommand, getBrief, getDetailed)( scopedCommand(GetCommand) { (s, scope, key, structure) => + val detailString = Project.details(structure, scope, key) logger(s).info(detailString) 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), "") def imports(extracted: Extracted): Seq[(String,Int)] =