From 8ad87183661af3ba2fdd8e1add438d941160f0e9 Mon Sep 17 00:00:00 2001 From: Mark Harrah Date: Tue, 15 Feb 2011 18:41:01 -0500 Subject: [PATCH] rename 'get' to 'inspect', merge 'delegates' command into it --- main/Act.scala | 11 ++++++--- main/CommandSupport.scala | 31 +++++++++++--------------- main/Main.scala | 47 ++++++++++----------------------------- main/Project.scala | 4 ++++ 4 files changed, 37 insertions(+), 56 deletions(-) diff --git a/main/Act.scala b/main/Act.scala index 0d3cfc9fd..2f7df53dd 100644 --- a/main/Act.scala +++ b/main/Act.scala @@ -89,11 +89,16 @@ object Act private[this] def actParser0(state: State) = { val extracted = Project extract state - import extracted._ - val defaultConf = (ref: ProjectRef) => if(Project.getProject(ref, structure).isDefined) defaultConfig(structure.data)(ref) else None showParser.flatMap { show => - scopedKey(structure.index.keyIndex, curi, cid, defaultConf, structure.index.keyMap) flatMap valueParser(state, structure, show) + scopedKeyParser(extracted) flatMap valueParser(state, extracted.structure, show) } } def showParser = token( ("show" ~ Space) ^^^ true) ?? false + def scopedKeyParser(state: State): Parser[ScopedKey[_]] = scopedKeyParser(Project extract state) + def scopedKeyParser(extracted: Extracted): Parser[ScopedKey[_]] = + { + import extracted._ + val defaultConf = (ref: ProjectRef) => if(Project.getProject(ref, structure).isDefined) defaultConfig(structure.data)(ref) else None + scopedKey(structure.index.keyIndex, curi, cid, defaultConf, structure.index.keyMap) + } } \ No newline at end of file diff --git a/main/CommandSupport.scala b/main/CommandSupport.scala index cd7163828..bf54f052e 100644 --- a/main/CommandSupport.scala +++ b/main/CommandSupport.scala @@ -41,22 +41,11 @@ EvalCommand + """ Evaluates the given Scala expression and prints the result and type. """ - 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. -""" - val LastGrepCommand = "last-grep" val lastGrepBrief = (LastGrepCommand + " ", "Shows lines from the last output for 'key' that match 'pattern'.") val lastGrepDetailed = LastGrepCommand + """ - is interpreted as a Scala expression of type sbt.Scoped and is typically a task key. is a regular expression interpreted by java.util.Pattern Lines that match 'pattern' from the last streams output associated with the key are displayed. See also """ + LastCommand + "." @@ -66,20 +55,26 @@ LastGrepCommand + """ val lastDetailed = LastCommand + """ - is interpreted as a Scala expression of type sbt.Scoped. The last streams output associated with the key (typically a task key) is redisplayed. See also """ + LastGrepCommand + "." - val GetCommand = "get" - val getBrief = (GetCommand + " ", "Prints the value for 'key', the defining scope, related definitions, and dependencies.") - val getDetailed = -GetCommand + """ + val InspectCommand = "inspect" + val inspectBrief = (InspectCommand + " ", "Prints the value for 'key', the defining scope, delegates, related definitions, and dependencies.") + val inspectDetailed = +InspectCommand + """ - 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. + "Dependencies" shows the settings that this setting depends on. + "Reverse dependencies" shows the settings that depend on this setting. + + When a key is resolved to a value, it may not actually be defined in the requested scope. + In this case, there is a defined search sequence. + "Delegates" shows the scopes that are searched for the key. + "Provided by" shows the scope that contained the value returned for the key. + + "Related" shows all of the scopes in which the key is defined. """ val SetCommand = "set" diff --git a/main/Main.scala b/main/Main.scala index 9cecb2db0..bea60a5c8 100644 --- a/main/Main.scala +++ b/main/Main.scala @@ -59,7 +59,7 @@ class xMain extends xsbti.AppMain object BuiltinCommands { 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, delegates,alias, append, last, lastGrep, nop, sessionCommand, act) + projects, project, setOnFailure, ifLast, multi, shell, set, inspect, eval, alias, append, last, lastGrep, nop, sessionCommand, act) def nop = Command.custom(s => success(() => s)) def ignore = Command.command(FailureWall)(identity) @@ -235,45 +235,22 @@ object BuiltinCommands val newSession = session.appendSettings( append map (a => (a, arg))) reapply(newSession, structure, s) } - def get = Command.single(GetCommand, getBrief, getDetailed)( scopedCommand(GetCommand) { (s, scope, key, structure) => - val detailString = Project.details(structure, scope, key) + def inspect = Command(InspectCommand, inspectBrief, inspectDetailed)(spacedKeyParser) { (s,sk) => + val detailString = Project.details(Project.structure(s), sk.scope, sk.key) logger(s).info(detailString) s - }) - def lastGrep = Command.single(LastGrepCommand, lastGrepBrief, lastGrepDetailed) { (s,arg) => - val (pattern, keyString) = arg.span(!_.isWhitespace) - if(keyString.isEmpty) - { - logger(s).error("Expected , found '" + arg + "'") - s.fail - } - else - { - val sc = scopedCommand(LastGrepCommand) { (s, scope, key, structure) => - Output.lastGrep(scope, key, structure.streams, pattern) - s - } - sc(s, keyString) - } } - def last = Command.single(LastCommand, lastBrief, lastDetailed)( scopedCommand(LastCommand) { (s, scope, key, structure) => - Output.last(scope, key, structure.streams) + def lastGrep = Command(LastGrepCommand, lastGrepBrief, lastGrepDetailed)(lastGrepParser) { case (s,(pattern,sk)) => + Output.lastGrep(sk.scope, sk.key, Project.structure(s).streams, pattern) 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) } + val spacedKeyParser = (s: State) => token(Space) ~> Act.scopedKeyParser(s) + def lastGrepParser(s: State) = (token(Space) ~> token(NotSpace, "")) ~ spacedKeyParser(s) + def last = Command(LastCommand, lastBrief, lastDetailed)(spacedKeyParser) { (s,sk) => + Output.last(sk.scope, sk.key, Project.structure(s).streams) + s + } + def autoImports(extracted: Extracted): EvalImports = new EvalImports(imports(extracted), "") def imports(extracted: Extracted): Seq[(String,Int)] = { diff --git a/main/Project.scala b/main/Project.scala index 0fd0a78e4..ce3ac2f2d 100644 --- a/main/Project.scala +++ b/main/Project.scala @@ -115,6 +115,9 @@ object Project extends Init[Scope] throw new Uninitialized(u.key, u.refKey, msg) } + def delegates(structure: Load.BuildStructure, scope: Scope, key: AttributeKey[_]): Seq[ScopedKey[_]] = + structure.delegates(scope).map(d => ScopedKey(d, key)) + def details(structure: Load.BuildStructure, scope: Scope, key: AttributeKey[_]): String = { val scoped = ScopedKey(scope,key) @@ -137,6 +140,7 @@ object Project extends Init[Scope] definedIn + "\n" + printScopes("Dependencies", depends) + printScopes("Reverse dependencies", reverse) + + printScopes("Delegates", delegates(structure, scope, key)) + printScopes("Related", related) } def reverseDependencies(cMap: CompiledMap, scoped: ScopedKey[_]): Iterable[ScopedKey[_]] =