mirror of https://github.com/sbt/sbt.git
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:
commit
20573e8631
|
|
@ -678,7 +678,10 @@ object BuiltinCommands {
|
||||||
def act: Command = Command.customHelp(Act.actParser, actHelp)
|
def act: Command = Command.customHelp(Act.actParser, actHelp)
|
||||||
|
|
||||||
def actHelp: State => Help =
|
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 =
|
def keysHelp(s: State): Help =
|
||||||
if (Project.isProjectLoaded(s))
|
if (Project.isProjectLoaded(s))
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ import Aggregation.{ KeyValue, Values }
|
||||||
import DefaultParsers._
|
import DefaultParsers._
|
||||||
import sbt.internal.util.Types.idFun
|
import sbt.internal.util.Types.idFun
|
||||||
import java.net.URI
|
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.internal.util.{ AttributeEntry, AttributeKey, AttributeMap, IMap, Settings, Util }
|
||||||
import sbt.util.Show
|
import sbt.util.Show
|
||||||
|
|
||||||
|
|
@ -427,7 +427,12 @@ object Act {
|
||||||
val akp = aggregatedKeyParser(extracted)
|
val akp = aggregatedKeyParser(extracted)
|
||||||
def evaluate(kvs: Seq[ScopedKey[_]]): Parser[() => State] = {
|
def evaluate(kvs: Seq[ScopedKey[_]]): Parser[() => State] = {
|
||||||
val preparedPairs = anyKeyValues(structure, kvs)
|
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 => () =>
|
evaluatingParser(state, showConfig)(preparedPairs) map { evaluate => () =>
|
||||||
{
|
{
|
||||||
val keyStrings = preparedPairs.map(pp => showKey.show(pp.key)).mkString(", ")
|
val keyStrings = preparedPairs.map(pp => showKey.show(pp.key)).mkString(", ")
|
||||||
|
|
@ -438,18 +443,19 @@ object Act {
|
||||||
}
|
}
|
||||||
action match {
|
action match {
|
||||||
case SingleAction => akp flatMap evaluate
|
case SingleAction => akp flatMap evaluate
|
||||||
case ShowAction | MultiAction =>
|
case ShowAction | PrintAction | MultiAction =>
|
||||||
rep1sep(akp, token(Space)).flatMap(kvss => evaluate(kvss.flatten))
|
rep1sep(akp, token(Space)).flatMap(kvss => evaluate(kvss.flatten))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private[this] final class ActAction
|
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] =
|
private[this] def actionParser: Parser[ActAction] =
|
||||||
token(
|
token(
|
||||||
((ShowCommand ^^^ ShowAction) |
|
((ShowCommand ^^^ ShowAction) |
|
||||||
|
(PrintCommand ^^^ PrintAction) |
|
||||||
(MultiTaskCommand ^^^ MultiAction)) <~ Space
|
(MultiTaskCommand ^^^ MultiAction)) <~ Space
|
||||||
) ?? SingleAction
|
) ?? SingleAction
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@ object CommandStrings {
|
||||||
val ProjectCommand = "project"
|
val ProjectCommand = "project"
|
||||||
val ProjectsCommand = "projects"
|
val ProjectsCommand = "projects"
|
||||||
val ShowCommand = "show"
|
val ShowCommand = "show"
|
||||||
|
val PrintCommand = "print"
|
||||||
val MultiTaskCommand = "all"
|
val MultiTaskCommand = "all"
|
||||||
val BootCommand = "boot"
|
val BootCommand = "boot"
|
||||||
|
|
||||||
|
|
@ -51,6 +52,18 @@ $ShowCommand <task>
|
||||||
|
|
||||||
Evaluates the specified task and display the value returned by the 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 PluginsCommand = "plugins"
|
||||||
val PluginCommand = "plugin"
|
val PluginCommand = "plugin"
|
||||||
def pluginsBrief = "Lists currently available plugins."
|
def pluginsBrief = "Lists currently available plugins."
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue