From cc143db6f73231250e257055ce27273fdbe94f20 Mon Sep 17 00:00:00 2001 From: falmarri Date: Mon, 3 Sep 2018 14:09:16 -0700 Subject: [PATCH] Make `show` output on stdout rather than to the logger Fixes #4184 --- main/src/main/scala/sbt/Main.scala | 7 +++++-- main/src/main/scala/sbt/internal/Act.scala | 14 ++++++++++---- .../main/scala/sbt/internal/CommandStrings.scala | 13 +++++++++++++ 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/main/src/main/scala/sbt/Main.scala b/main/src/main/scala/sbt/Main.scala index c2c523475..eed5a35c1 100644 --- a/main/src/main/scala/sbt/Main.scala +++ b/main/src/main/scala/sbt/Main.scala @@ -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.""") - } + } ) } diff --git a/main/src/main/scala/sbt/internal/Act.scala b/main/src/main/scala/sbt/internal/Act.scala index 953598933..e4ca77fbf 100644 --- a/main/src/main/scala/sbt/internal/Act.scala +++ b/main/src/main/scala/sbt/internal/Act.scala @@ -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 diff --git a/main/src/main/scala/sbt/internal/CommandStrings.scala b/main/src/main/scala/sbt/internal/CommandStrings.scala index 534945f18..2704d4f5b 100644 --- a/main/src/main/scala/sbt/internal/CommandStrings.scala +++ b/main/src/main/scala/sbt/internal/CommandStrings.scala @@ -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 Evaluates the specified task and display the value returned by the task.""" + def printHelp = Help(PrintCommand, (s"$PrintCommand ", printBrief), printDetailed) + def printBrief = + "Prints the result of evaluating the setting or task associated with 'key' to standard output." + def printDetailed = + s"""$PrintCommand + + Prints the value of the specified setting. + +$PrintCommand + + Evaluates the specified task and print the value returned by the task.""" + val PluginsCommand = "plugins" val PluginCommand = "plugin" def pluginsBrief = "Lists currently available plugins."