rename 'get' to 'inspect', merge 'delegates' command into it

This commit is contained in:
Mark Harrah 2011-02-15 18:41:01 -05:00
parent cc06667f3e
commit 8ad8718366
4 changed files with 37 additions and 56 deletions

View File

@ -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)
}
}

View File

@ -41,22 +41,11 @@ EvalCommand + """ <expression>
Evaluates the given Scala expression and prints the result and type.
"""
def DelegatesCommand = "delegates"
def delegatesBrief = (DelegatesCommand + " <key>", "Prints the scopes searched when resolving the given key.")
def delegatesDetailed =
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.
"""
val LastGrepCommand = "last-grep"
val lastGrepBrief = (LastGrepCommand + " <pattern> <key>", "Shows lines from the last output for 'key' that match 'pattern'.")
val lastGrepDetailed =
LastGrepCommand + """ <pattern> <key>
<key> is interpreted as a Scala expression of type sbt.Scoped and is typically a task key.
<pattern> 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 + """ <pattern> <key>
val lastDetailed =
LastCommand + """ <key>
<key> 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 + " <key>", "Prints the value for 'key', the defining scope, related definitions, and dependencies.")
val getDetailed =
GetCommand + """ <key>
val InspectCommand = "inspect"
val inspectBrief = (InspectCommand + " <key>", "Prints the value for 'key', the defining scope, delegates, related definitions, and dependencies.")
val inspectDetailed =
InspectCommand + """ <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.
"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"

View File

@ -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 <pattern> <key>, 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, "<pattern>")) ~ 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), "<auto-imports>")
def imports(extracted: Extracted): Seq[(String,Int)] =
{

View File

@ -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[_]] =