From 06724d1c4bd053ab6e91af446c0d65e3c2a0173d Mon Sep 17 00:00:00 2001 From: Eugene Yokota Date: Thu, 15 Sep 2016 01:34:41 -0400 Subject: [PATCH] Rename early command to `early(command)` Fixes #2734, Ref #1041 e93c4450a1a06fe6c67df821c65fea302cecca84 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. --- .../src/main/scala/sbt/BasicCommandStrings.scala | 15 ++++++--------- .../src/main/scala/sbt/BasicCommands.scala | 5 ++++- sbt/src/sbt-test/actions/early-command/build.sbt | 1 + sbt/src/sbt-test/actions/early-command/test | 1 + 4 files changed, 12 insertions(+), 10 deletions(-) create mode 100644 sbt/src/sbt-test/actions/early-command/build.sbt create mode 100644 sbt/src/sbt-test/actions/early-command/test diff --git a/main-command/src/main/scala/sbt/BasicCommandStrings.scala b/main-command/src/main/scala/sbt/BasicCommandStrings.scala index 88ae4a2ca..f9be89146 100644 --- a/main-command/src/main/scala/sbt/BasicCommandStrings.scala +++ b/main-command/src/main/scala/sbt/BasicCommandStrings.scala @@ -60,21 +60,18 @@ ${runEarly(level.toString)} * if no other commands are passed, interactive mode is still entered """ - def runEarly(command: String) = { - val sep = if (command.isEmpty || Character.isLetter(command.charAt(0))) "" else " " - s"$EarlyCommand$sep$command" - } + def runEarly(command: String) = s"$EarlyCommand($command)" private[sbt] def isEarlyCommand(s: String): Boolean = { - s.startsWith(EarlyCommand) && s != Compat.FailureWall && s != Compat.ClearOnFailure + s.startsWith(EarlyCommand + "(") && s.endsWith(")") } - val EarlyCommand = "--" - val EarlyCommandBrief = (s"$EarlyCommand", "Schedules a command to run before other commands on startup.") + val EarlyCommand = "early" + val EarlyCommandBrief = (s"$EarlyCommand()", "Schedules a command to run before other commands on startup.") val EarlyCommandDetailed = - s"""$EarlyCommand + s"""$EarlyCommand() 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 = "<" diff --git a/main-command/src/main/scala/sbt/BasicCommands.scala b/main-command/src/main/scala/sbt/BasicCommands.scala index 517e3a9dd..1a7e32f54 100644 --- a/main-command/src/main/scala/sbt/BasicCommands.scala +++ b/main-command/src/main/scala/sbt/BasicCommands.scala @@ -24,7 +24,10 @@ object BasicCommands { def ignore = Command.command(FailureWall)(idFun) def early = Command.arb(earlyParser, earlyHelp) { (s, other) => other :: s } - private[this] def earlyParser = (s: State) => token(EarlyCommand).flatMap(_ => otherCommandParser(s)) + private[this] def earlyParser = (s: State) => + token(EarlyCommand + "(") flatMap { _ => + otherCommandParser(s) <~ token(")") + } private[this] def earlyHelp = Help(EarlyCommand, EarlyCommandBrief, EarlyCommandDetailed) def help = Command.make(HelpCommand, helpBrief, helpDetailed)(helpParser) diff --git a/sbt/src/sbt-test/actions/early-command/build.sbt b/sbt/src/sbt-test/actions/early-command/build.sbt new file mode 100644 index 000000000..c128b140e --- /dev/null +++ b/sbt/src/sbt-test/actions/early-command/build.sbt @@ -0,0 +1 @@ +lazy val root = (project in file(".")) diff --git a/sbt/src/sbt-test/actions/early-command/test b/sbt/src/sbt-test/actions/early-command/test new file mode 100644 index 000000000..9dd08d035 --- /dev/null +++ b/sbt/src/sbt-test/actions/early-command/test @@ -0,0 +1 @@ +> early(error)