Merge pull request #4341 from Falmarri/feature/show-output-4184

Add `print` command that mimics `show`, but to standard output, not the logger
This commit is contained in:
eugene yokota 2018-09-17 12:33:25 -04:00 committed by GitHub
commit 20573e8631
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 5 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))

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."