Make `show` output on stdout rather than to the logger

Fixes #4184
This commit is contained in:
falmarri 2018-09-03 14:09:16 -07:00
parent 4c3cd4e535
commit cc143db6f7
3 changed files with 28 additions and 6 deletions

View File

@ -678,7 +678,10 @@ object BuiltinCommands {
def act: Command = Command.customHelp(Act.actParser, actHelp)
def actHelp: State => Help =
s => CommandStrings.showHelp ++ CommandStrings.multiTaskHelp ++ keysHelp(s)
s =>
CommandStrings.showHelp ++ CommandStrings.printHelp ++ CommandStrings.multiTaskHelp ++ keysHelp(
s
)
def keysHelp(s: State): Help =
if (Project.isProjectLoaded(s))
@ -824,7 +827,7 @@ object BuiltinCommands {
if (version != app.id.version()) {
state.log.warn(s"""sbt version mismatch, current: ${app.id
.version()}, in build.properties: "$version", use 'reboot' to use the new value.""")
}
}
)
}

View File

@ -15,7 +15,7 @@ import Aggregation.{ KeyValue, Values }
import DefaultParsers._
import sbt.internal.util.Types.idFun
import java.net.URI
import sbt.internal.CommandStrings.{ MultiTaskCommand, ShowCommand }
import sbt.internal.CommandStrings.{ MultiTaskCommand, ShowCommand, PrintCommand }
import sbt.internal.util.{ AttributeEntry, AttributeKey, AttributeMap, IMap, Settings, Util }
import sbt.util.Show
@ -427,7 +427,12 @@ object Act {
val akp = aggregatedKeyParser(extracted)
def evaluate(kvs: Seq[ScopedKey[_]]): Parser[() => State] = {
val preparedPairs = anyKeyValues(structure, kvs)
val showConfig = Aggregation.defaultShow(state, showTasks = action == ShowAction)
val showConfig = if (action == PrintAction) {
Aggregation.ShowConfig(true, true, println, false)
} else {
Aggregation.defaultShow(state, showTasks = action == ShowAction)
}
evaluatingParser(state, showConfig)(preparedPairs) map { evaluate => () =>
{
val keyStrings = preparedPairs.map(pp => showKey.show(pp.key)).mkString(", ")
@ -438,18 +443,19 @@ object Act {
}
action match {
case SingleAction => akp flatMap evaluate
case ShowAction | MultiAction =>
case ShowAction | PrintAction | MultiAction =>
rep1sep(akp, token(Space)).flatMap(kvss => evaluate(kvss.flatten))
}
}
}
private[this] final class ActAction
private[this] final val ShowAction, MultiAction, SingleAction = new ActAction
private[this] final val ShowAction, MultiAction, SingleAction, PrintAction = new ActAction
private[this] def actionParser: Parser[ActAction] =
token(
((ShowCommand ^^^ ShowAction) |
(PrintCommand ^^^ PrintAction) |
(MultiTaskCommand ^^^ MultiAction)) <~ Space
) ?? SingleAction

View File

@ -19,6 +19,7 @@ object CommandStrings {
val ProjectCommand = "project"
val ProjectsCommand = "projects"
val ShowCommand = "show"
val PrintCommand = "print"
val MultiTaskCommand = "all"
val BootCommand = "boot"
@ -51,6 +52,18 @@ $ShowCommand <task>
Evaluates the specified task and display the value returned by the task."""
def printHelp = Help(PrintCommand, (s"$PrintCommand <key>", printBrief), printDetailed)
def printBrief =
"Prints the result of evaluating the setting or task associated with 'key' to standard output."
def printDetailed =
s"""$PrintCommand <setting>
Prints the value of the specified setting.
$PrintCommand <task>
Evaluates the specified task and print the value returned by the task."""
val PluginsCommand = "plugins"
val PluginCommand = "plugin"
def pluginsBrief = "Lists currently available plugins."