Rename early command to `early(command)`

Backports #2741, Fixes #1041

e93c445 added a feature called early command, which uses `--` as a
prefix to denote some commands that runs ahead of session loading.
While the feature might be useful especially for logging, `--` is too
useful just for this purpose.

In addition, this adds log level commands with single `-`, such as
-error to treat them as early commands; and keeps `--` variant for log
level for backward compatibility.
This commit is contained in:
Eugene Yokota 2016-09-15 03:06:12 -04:00
parent 5cc4f2fadb
commit ee718e8700
5 changed files with 34 additions and 11 deletions

View File

@ -60,7 +60,7 @@ object BasicCommandStrings {
This will be used as the default level for logging from commands, settings, and tasks. This will be used as the default level for logging from commands, settings, and tasks.
Any explicit `logLevel` configuration in a project overrides this setting. Any explicit `logLevel` configuration in a project overrides this setting.
${runEarly(level.toString)} -$level
Sets the global logging level as described above, but does so before any other commands are executed on startup, including project loading. Sets the global logging level as described above, but does so before any other commands are executed on startup, including project loading.
This is useful as a startup option: This is useful as a startup option:
@ -68,21 +68,23 @@ ${runEarly(level.toString)}
* if no other commands are passed, interactive mode is still entered * if no other commands are passed, interactive mode is still entered
""" """
def runEarly(command: String) = { def runEarly(command: String) = s"$EarlyCommand($command)"
val sep = if (command.isEmpty || Character.isLetter(command.charAt(0))) "" else " "
s"$EarlyCommand$sep$command"
}
private[sbt] def isEarlyCommand(s: String): Boolean = { private[sbt] def isEarlyCommand(s: String): Boolean = {
s.startsWith(EarlyCommand) && s != Compat.FailureWall && s != Compat.ClearOnFailure val levelShortOptions = Level.values.toSeq map { "-" + _ }
val levelLongOptions = Level.values.toSeq map { "--" + _ }
(s.startsWith(EarlyCommand + "(") && s.endsWith(")")) ||
(levelShortOptions contains s) ||
(levelLongOptions contains s)
} }
val EarlyCommand = "--" val OldEarlyCommand = "--"
val EarlyCommandBrief = (s"$EarlyCommand<command>", "Schedules a command to run before other commands on startup.") val EarlyCommand = "early"
val EarlyCommandBrief = (s"$EarlyCommand(<command>)", "Schedules a command to run before other commands on startup.")
val EarlyCommandDetailed = val EarlyCommandDetailed =
s"""$EarlyCommand<command> s"""$EarlyCommand(<command>)
Schedules an early command, which will be run before other commands on the command line. Schedules an early command, which will be run before other commands on the command line.
The order is preserved between all early commands, so `sbt --a --b` executes `a` and `b` in order. The order is preserved between all early commands, so `sbt "early(a)" "early(b)"` executes `a` and `b` in order.
""" """
def ReadCommand = "<" def ReadCommand = "<"

View File

@ -22,7 +22,18 @@ object BasicCommands {
def ignore = Command.command(FailureWall)(idFun) def ignore = Command.command(FailureWall)(idFun)
def early = Command.arb(earlyParser, earlyHelp) { (s, other) => other :: s } def early = Command.arb(earlyParser, earlyHelp) { (s, other) => other :: s }
private[this] def earlyParser = (s: State) => token(EarlyCommand).flatMap(_ => otherCommandParser(s)) private[this] def levelParser: Parser[String] =
token(Level.Debug.toString) | token(Level.Info.toString) | token(Level.Warn.toString) | token(Level.Error.toString)
private[this] def earlyParser: State => Parser[String] = (s: State) =>
(token(EarlyCommand + "(") flatMap { _ =>
otherCommandParser(s) <~ token(")")
}) |
(token("-") flatMap { _ =>
levelParser
}) |
(token(OldEarlyCommand) flatMap { _ =>
levelParser
})
private[this] def earlyHelp = Help(EarlyCommand, EarlyCommandBrief, EarlyCommandDetailed) private[this] def earlyHelp = Help(EarlyCommand, EarlyCommandBrief, EarlyCommandDetailed)
def help = Command.make(HelpCommand, helpBrief, helpDetailed)(helpParser) def help = Command.make(HelpCommand, helpBrief, helpDetailed)(helpParser)

6
notes/0.13.13/early.md Normal file
View File

@ -0,0 +1,6 @@
### Fixes with compatibility implications
- sbt 0.13.13 renames the early command that was added in 0.13.1 to `early(<command>)`. This fixes the regression [#1041][1041]. For backward compatibility `--error`, `--warn`, `--info`, and `--debug` will continue to function during 0.13 series, but it is strongly encouraged to migrate to the single hyphen option: `-error`, `-warn`, `-info`, and `-debug`. [@eed3si9n][@eed3si9n]
[1041]: https://github.com/sbt/sbt/issues/1041
[@eed3si9n]: https://github.com/eed3si9n

View File

@ -0,0 +1 @@
lazy val root = (project in file("."))

View File

@ -0,0 +1,3 @@
> early(error)
> -error
> --error