From 3e201cee4d830353f9a076e863d22cdc623f9ac8 Mon Sep 17 00:00:00 2001 From: Nafer Sanabria Date: Sun, 8 Apr 2018 10:51:54 -0500 Subject: [PATCH] Add lastGrep command --- main/src/main/scala/sbt/Main.scala | 12 +++++++++--- .../main/scala/sbt/internal/CommandStrings.scala | 15 ++++++++++++++- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/main/src/main/scala/sbt/Main.scala b/main/src/main/scala/sbt/Main.scala index 4f4ef57d6..c19d44c40 100644 --- a/main/src/main/scala/sbt/Main.scala +++ b/main/src/main/scala/sbt/Main.scala @@ -40,7 +40,6 @@ import sbt.internal.util.{ Types } import sbt.util.{ Level, Logger, Show } - import sbt.internal.util.complete.{ DefaultParsers, Parser } import sbt.internal.inc.ScalaInstance import sbt.compiler.EvalImports @@ -52,7 +51,6 @@ import xsbti.compile.CompilerCache import scala.annotation.tailrec import sbt.io.IO import sbt.io.syntax._ - import java.io.{ File, IOException } import java.net.URI import java.util.{ Locale, Properties } @@ -198,6 +196,7 @@ object BuiltinCommands { startServer, eval, last, + oldLastGrep, lastGrep, export, boot, @@ -452,8 +451,15 @@ object BuiltinCommands { s } + @deprecated("Use `lastGrep` instead.", "1.2.0") + def oldLastGrep: Command = + lastGrepCommand(OldLastGrepCommand, oldLastGrepBrief, oldLastGrepDetailed) + def lastGrep: Command = - Command(LastGrepCommand, lastGrepBrief, lastGrepDetailed)(lastGrepParser) { + lastGrepCommand(LastGrepCommand, lastGrepBrief, lastGrepDetailed) + + private def lastGrepCommand(name: String, briefHelp: (String, String), detail: String): Command = + Command(name, briefHelp, detail)(lastGrepParser) { case (s, (pattern, Some(sks))) => val (str, _, display) = extractLast(s) Output.lastGrep(sks, str.streams(s), pattern, printLast)(display) diff --git a/main/src/main/scala/sbt/internal/CommandStrings.scala b/main/src/main/scala/sbt/internal/CommandStrings.scala index dc070a468..278985b64 100644 --- a/main/src/main/scala/sbt/internal/CommandStrings.scala +++ b/main/src/main/scala/sbt/internal/CommandStrings.scala @@ -57,10 +57,23 @@ $ShowCommand def pluginsDetailed = pluginsBrief // TODO: expand val LastCommand = "last" - val LastGrepCommand = "last-grep" + val OldLastGrepCommand = "last-grep" + val LastGrepCommand = "lastGrep" val ExportCommand = "export" val ExportStream = "export" + val oldLastGrepBrief = + (OldLastGrepCommand, "Shows lines from the last output for 'key' that match 'pattern'.") + val oldLastGrepDetailed = + s"""$OldLastGrepCommand + Displays lines from the logging of previous commands that match `pattern`. + +$OldLastGrepCommand [key] + Displays lines from logging associated with `key` that match `pattern`. The key typically refers to a task (for example, test:compile). The logging that is displayed is restricted to the logging for that particular task. + + is a regular expression interpreted by java.util.Pattern. Matching text is highlighted (when highlighting is supported and enabled). + See also '$LastCommand'.""" + val lastGrepBrief = (LastGrepCommand, "Shows lines from the last output for 'key' that match 'pattern'.") val lastGrepDetailed =