'show' can prefix task to display its result

This commit is contained in:
Mark Harrah 2011-02-10 08:13:48 -05:00
parent 462b0f2237
commit 3de34c6569
2 changed files with 13 additions and 8 deletions

View File

@ -60,19 +60,19 @@ object Act
def optProjectRef(index: KeyIndex, currentBuild: URI, currentProject: String) =
projectRef(index, currentBuild) ?? ProjectRef(Some(currentBuild), Some(currentProject))
def valueParser(s: State, structure: BuildStructure)(key: ScopedKey[_]): Parser[() => State] =
def valueParser(s: State, structure: BuildStructure, show: Boolean)(key: ScopedKey[_]): Parser[() => State] =
structure.data.get(key.scope, key.key) match
{
case None => failure("Invalid setting or task")
case Some(input: InputTask[_]) => applyTask(s, structure, input.parser)
case Some(task: Task[_]) => applyTask(s, structure, success(task))
case Some(input: InputTask[_]) => applyTask(s, structure, input.parser, show)
case Some(task: Task[_]) => applyTask(s, structure, success(task), show)
case Some(v) => success(() => { logger(s).info(v.toString); s})
}
def applyTask(s: State, structure: Load.BuildStructure, p: Parser[Task[_]]): Parser[() => State] =
def applyTask(s: State, structure: Load.BuildStructure, p: Parser[Task[_]], show: Boolean): Parser[() => State] =
Command.applyEffect(p) { t =>
import EvaluateTask._
val result = withStreams(structure){ str => runTask(t)(nodeView(s, str)) }
processResult(result, logger(s))
processResult(result, logger(s), show)
s
}
def actParser(s: State): Parser[() => State] =
@ -82,6 +82,9 @@ object Act
val extracted = Project extract state
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) flatMap valueParser(state, structure)
showParser.flatMap { show =>
scopedKey(structure.index.keyIndex, curi, cid, defaultConf, structure.index.keyMap) flatMap valueParser(state, structure, show)
}
}
def showParser = token( ("show" ~ Space) ^^^ true) ?? false
}

View File

@ -154,10 +154,12 @@ object EvaluateTask
try { x.run(root)(service) } finally { shutdown() }
}
def processResult[T](result: Result[T], log: Logger): T =
def processResult[T](result: Result[T], log: Logger, show: Boolean = false): T =
result match
{
case Value(v) => v
case Value(v) =>
if(show) println("Result: " + v)
v
case Inc(inc) =>
log.error(Incomplete.show(inc, true))
error("Task did not complete successfully")